Im having problem with building my project, i.e, "goapp serve".
I get this message:
Failed to build Go application: (Executed command: /Users/simon/go_appengine/goroot/bin/go-app-builder -app_base /Users/simon/Programming/golang_projects/src/googleglass_backend -arch 6 -dynamic -goroot /Users/simon/go_appengine/goroot -gopath /Users/simon/Programming/golang_projects -nobuild_files ^^$ -incremental_rebuild -unsafe -print_extras_hash handlers/mainpage.go types/user.go types/data.go handlers/utils.go server.go)
2017/01/16 14:04:30 go-app-builder: Failed parsing input: app file data.go conflicts with same file imported from GOPATH
My project structure looks like this:
golang_projects
bin
...
pkg
...
src
googleglass_backend
app.yaml
handlers
utils.go
mainpage.go
index.yaml
server.go
types
data.go
user.go
My GOPATH looks like this:
/Users/simon/Programming/golang_projects
I dont know what data.go could be conflicting with?
My server.go file:
package main
import (
"googleglass_backend/handlers"
"googleglass_backend/types"
"github.com/gorilla/mux"
"encoding/gob"
"net/http"
"github.com/rs/cors"
)
func init() {
router := mux.NewRouter()
gob.Register(types.User{})
//For all includes in html files
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("web/static/"))))
router.HandleFunc("/", handlers.IndexTemplate)
handler := cors.Default().Handler(router)
http.Handle("/", handler)
}
Contents of data.go:
package types
import (
"time"
)
type Data struct {
xaxis int
yaxis int
beacon_1 int
beacon_2 int
beacon_3 int
RegisterTime time.Time
}
Related
I'm trying to use AssemblyScript to build a WebAssembly inference engine for a TensorFlow.js model that I have.
I started with essentially the quickstart AssemblyScript app (which works great) and then simply added #tensorflow/tfjs to my dependencies:
$ npm install --save #tensorflow/tfjs
and added an import to assembly/index.ts:
import * as tf from "#tensorflow/tfjs";
Full code here on Github
This results in an error when I build it:
$ npm run asbuild
> test-assemblyscript#1.0.0 asbuild
> npm run asbuild:untouched && npm run asbuild:optimized
> test-assemblyscript#1.0.0 asbuild:untouched
> asc assembly/index.ts --target debug
ERROR TS6054: File '~lib/#tensorflow/tfjs.ts' not found.
import * as tf from "#tensorflow/tfjs";
~~~~~~~~~~~~~~~~~~
in assembly/index.ts(1,21)
FAILURE 1 parse error(s)
Am I misunderstanding the import syntax? I am puzzled why it would be looking in ~lib for this versus node_modules.
If you are sure the module you are trying to import is assemblyscript files, you can import with something like this ./node_modules/#tenderflow/tfjs.
I am not sure if #tensorflow has assembly files built, but I did that on assemblyscript-json for assemblyscript#0.19.8 (0.25.2 doesn't have that problem).
For example
assemblyscript-json has exported assemblyscript files from its package, so I can do this (ref)
import { JSON } from './node_modules/assemblyscript-json/assembly';
export function formatJsonString(jsonString: string): string {
const jsonObj: JSON.Obj = <JSON.Obj>JSON.parse(jsonString);
return jsonObj.stringify();
}
There's a problem where I don't know why a context.Context was changed once I pass it to a different package on Google App Engine.
The following code works fine when running on App Engine:
package main
import (
"net/http"
"log"
"google.golang.org/appengine"
)
func main() {
http.HandleFunc("/", myHandler)
appengine.Main()
}
func myHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
account, err := appengine.ServiceAccount(ctx)
if err != nil {
log.Println("[myHandler] error:", err)
} else {
log.Println("[myHandler] ServiceAccount:", account)
}
w.Write([]byte("ok"))
}
I could retrieve the ServiceAccount successfully when accessing /, and everything was good.
However, when I passed the context from main.go to another package, the function call didn't work. The following was added to main.go:
import (
// other stuff
"github.com/adlerhsieh/q_context/handlers"
)
func main() {
http.HandleFunc("/", myHandler)
appengine.Main()
}
func myHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
account, err := appengine.ServiceAccount(ctx)
if err != nil {
log.Println("[myHandler] error:", err)
} else {
log.Println("[myHandler] ServiceAccount:", account)
}
handlers.AnotherFunc(ctx) // <--- added this
w.Write([]byte("ok"))
}
Another package:
package handlers
import (
"log"
"context"
"google.golang.org/appengine"
)
func AnotherFunc(ctx context.Context) {
account, err := appengine.ServiceAccount(ctx)
if err != nil {
log.Println("[AnotherFunc] error:", err)
} else {
log.Println("[AnotherFunc] ServiceAccount:", account)
}
}
When I ran it on App Engine, the log said:
2019/09/04 09:36:30 [myHandler] ServiceAccount: myaccount#gmail.com
2019/09/04 09:36:30 [AnotherFunc] error: not an App Engine context
The function calls are the same, but just in different packages. I dug in the package itself and found that it uses the key here (which leads to here) to setup the context. And here to check whether that value was setup properly. However, that value seem to be modified/changed so that the second function call couldn't get it. Even if I omitted the first function call and went straight to the second one, it still has the same error.
Any idea why context object was modified when passing to another package?
The following is my app.yaml:
runtime: go111
service: default
instance_class: F1
automatic_scaling:
min_idle_instances: 0
max_idle_instances: automatic
min_pending_latency: automatic
max_pending_latency: automatic
max_concurrent_requests: 30
handlers:
- url: /.*
script: auto
login: admin
nobuild_files:
- vendor
env_variables:
ENV: 'dev'
GO111MODULE: 'off'
Here is the GitHub repo link.
Thank you!
It turns out that my code actually worked. It's because of some other operation error.
However, I'll just post the issue that actually caused it so it can help those who have the same issue.
With the new go111 runtime, it treats packages from non-root directory or its subdirectories as a different type of package. This caused the problem with "not an App Engine context". I'll just call it an "outcast" package for now (cause I'm not entirely sure why's that).
For example:
- appengine
- main.go
- handlers
- handlers.go <-- this is a regular package
- appengine
- main.go
- handlers
- handlers.go < -- this is an outcast package
An outcast package would have issues handling context.Context generated from App Engine, as pointed out in my question.
The mechanism of App Engine knowing that the context is created from App Engine, is using a built-in value that can only be retrieved from its internal package (with an un-exported pointer-string key). When passing the context to an outcast package, we can no longer retrieve the value from the context. It's still a mystery for me that why the value disappeared, but it's probably because of some Go compiling mechanism.
The solution would be moving the main.go to the top-level directory in the project, so that there would be no outcast package anywhere.
I have created a react typescript project with CRA with the command yarn create react-app my-app --typescript
now I have a module foo installed that does not have any typing not by default, not in defentlytyped repository.
i.e. in a component, I have
import {bar} from 'foo';
which throws error Type error: Could not find a declaration file for module 'foo'. '/*/node_modules/foo/dist/entry.js' implicitly has an 'any' type.
I created foo.d.ts in types folder at the root of the project like
declare module 'foo'{ import * as React from 'react' }
just to have the foo as type any but still, get the same error. it seems that whatever compiler (webpack,other transpiler) does not find the declaration at types folder
how can I add custom type declaration to the project?
Here is a real use-case example.
I managed to integrate kendo-ui-core into CRA+Typescript.
The problem was that there are no typings for kendo-ui-core, namely the typings have a different name: #types/kendo-ui
Typescript was complaining about not having type definitions
To resolve the issue, create a file called kendo-ui-core.d.ts in your /src directory with the following contents:
// src/kendo-ui-core.d.ts
declare module 'kendo-ui-core' {
import * as KendoTypings from '#types/kendo-ui';
export = KendoTypings;
}
This works:
/* create src/CustomTypes.ts */
namespace MyCustomType {
export type foo = number;
}
export default MyCustomType;
use like this:
import MyCustomType from "src/CustomTypes";
const num: MyCustomType.foo = 123;
I'm getting following error when i execute sencha app build
[ERR] BUILD FAILED
[ERR] com.sencha.exceptions.ExBuild: com.sencha.exceptions.ExBuild: Failed to find any files for extjs-build\app\app\Application.js::ClassRequire::Object
extjs-build\app\app\Application.js looks like
Ext.define('PM.app.Application', {
extend: 'Ext.app.Application',
requires: [
'PM.Object'
]
}
A file for class PM.Object exists. The path is: extjs-build\app\Object.js and extends Ext.Object with some extra functions:
PM.Object = Ext.apply(Ext.Object, {
...: function() {}
}
The extjs-build\.sencha\app\sencha.cfg file:
# The path(s) to application javascript sources (comma separated)
app.classpath=${app.dir}/app
My Directory looks like:
/extjs-build/
.sencha/
app/
app/
Application.js
data/
SomeStore.js
app.js
Object.js
ext/
src/
I'm running sencha app build from /extjs-build/
Ext.Loader handles the issue correct (/extjs-build/app/app.js)
Ext.Loader.setConfig({
paths: {
'PM': './extjs-build/app'
}
});
Ext.application('PM.app.Application');
Any suggestions?
Your PM.Object path (extjs-build\app) is outside the build directory of you app (extjs-build\app\app)
I suspect you are running sencha app build in extjs-build\app which means the compiler will look for js files in extjs-build\app\app\ (this is because app.classpath=${app.dir}/app)
In your sencha.cfg you can change the classpath. Or move that file into the extjs-build/app/app directory.
I solved this issue by adding an empty
Ext.define('PM.Object', {
});
in file extjs-build/app/Object.js.
How to import local packages in Golang + GAE?
I wanna something like this:
app/
-app.yaml
-/my_app
--my_app.go
--/package1
---package1.go
Listing of my_app.go:
package my_app
import (
"http"
"./package1"
)
func init() {
http.HandleFunc("/", package1.index)
}
Listing of package1.go:
package package1
import (
"http"
"fmt"
)
func index (w http.ResponseWriter, r * http.Request) {
fmt.Fprint(w, "I'm index page =) ")
}
I this case I have an error like:
/path/to/project/my_app/my_app.go:5: can't find import: ./package1
2011/11/03 10:50:51 go-app-builder: Failed building app: failed running 6g: exit status 1
Thanks for help.
As noted in the comments to dupoxy's answer, the way to import a local package in the given situation is to import as "my_app/package1":
import (
"http"
"my_app/package1"
)
You either need to link or copy the packages to your application directory. The path relative to the root of the application directory should match the import path. To use package1, you should configure your app directory to look like this:
app.yaml
yourapp/yourapp.go
package1/package1.go
from https://groups.google.com/d/msg/golang-nuts/coEvrWIJGTs/75GzcefKVcIJ