astaxie / beegae

beego for GAE
Other
38 stars 11 forks source link

Basic Example of using Beegae #18

Closed salmosri closed 9 years ago

salmosri commented 9 years ago

Hi,

I am currently finding it a little difficult to get a hello world using beegae. There doesn't seem to be any documentation on here about usage of this?

Currently I have attempted the following:

salmosri@springs:~/Workspace/go/src/hellobeegae$ go get github.com/astaxie/beegae
package appengine: unrecognized import path "appengine"

This does seem to import the beegae library to the correct place (the error/warning could be resolved I hope?)

Created a Project Folder called hellobeegae and added the following

app.yaml

application: hellobeegae
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

What to do next is a little unclear? Can you point to any documentation to get this up and running?

Unsuccessful attempts:

  1. Create a new bee project
salmosri@springs:~/Workspace/go/src$ bee new hellobeegae
[INFO] Creating application...
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/conf/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/controllers/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/models/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/routers/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/tests/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/static/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/static/js/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/static/css/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/static/img/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/views/
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/conf/app.conf
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/controllers/default.go
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/views/index.tpl
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/routers/router.go
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/tests/default_test.go
/usr/local/google/home/salmosri/Workspace/go/src/hellobeegae/main.go
2014/12/29 19:33:23 [SUCC] New application successfully created!

Edit the main.go to change the import from beego to beegae

package main

import (
    "hellobeegae/routers"
    "github.com/astaxie/beegae"
)

func main() {
    beego.Run()
}

Edit the default.go to change the import from beego to beegae

package controllers

import (
    "github.com/astaxie/beegae"
)

type MainController struct {
    beego.Controller
}

func (c *MainController) Get() {
    c.Data["Website"] = "beego.me"
    c.Data["Email"] = "astaxie@gmail.com"
    c.TplNames = "index.tpl"
}

Edit the router.go to change the import from beego to beegae

package routers

import (
    "hellobeegae/controllers"
    "github.com/astaxie/beegae"
)

func init() {
    beego.Router("/", &controllers.MainController{})
}

Then executing the app with goapp serve

salmosri@springs:~/Workspace/go/src/hellobeegae$ goapp serve
INFO     2014-12-30 00:57:04,411 devappserver2.py:745] Skipping SDK update check.
INFO     2014-12-30 00:57:04,415 api_server.py:172] Starting API server at: http://localhost:45786
INFO     2014-12-30 00:57:04,442 dispatcher.py:186] Starting module "default" running at: http://localhost:8080
INFO     2014-12-30 00:57:04,443 admin_server.py:118] Starting admin server at: http://localhost:8000
ERROR    2014-12-30 00:57:05,452 go_runtime.py:171] Failed to build Go application: (Executed command: /usr/local/google/home/salmosri/google-cloud-sdk/platform/google_appengine/goroot/bin/go-app-builder -app_base /usr/local/google/home/salmosri/Workspace/go/src/hellobeegae -arch 6 -dynamic -goroot /usr/local/google/home/salmosri/google-cloud-sdk/platform/google_appengine/goroot -nobuild_files ^^$ -unsafe -gopath /usr/local/google/home/salmosri/Workspace/go -print_extras_hash main.go routers/router.go controllers/default.go tests/default_test.go)

2014/12/29 19:57:05 go-app-builder: Failed parsing input: app file router.go conflicts with same file imported from GOPATH

Any advice on resolving this?

someone1 commented 9 years ago

Two things:

  1. When you fetch the repository, use goapp get as this will include the appengine package
  2. This is an issue with how the SDK is setup. Try creating a folder in your app root called main and move ONLY the views folder, the app.yaml file, and the main.go files. Keep everything else the same and try compiling then. Alternatively, use relative imports instead of full-path imports (not desirable as it goes against idiomatic Go but it will work)

Both of these are less of beegae specific questions but rather a lack of understanding on how to use the AppEngine go tools (mostly because they lack any decent documentation). I guess most users of beegae are familiar with these sort of caveats and how to use the tools which is why this sort of documentation was never written.

I'll be sure to put your write-up (with some modification) in a future release. There's also the "examples" directory that you can take a look at on how to structure your beegae code!

someone1 commented 9 years ago

FYI - I updated beegae and added parts into the readme on how to get started. I hope this helps!