2

I was following this tutorial on using Go + Revel + MongoDB. But as I starting the application, I got this error:

The Go code api-go/app/init.go does not compile: undefined: revel.LoadConfig

along with other errors as I look in the terminal.

ERROR 2016/10/18 17:15:06 build.go:108: # api-go/app
api-go/app/init.go:41: undefined: revel.LoadConfig
api-go/app/init.go:43: undefined: log in log.Fatalf
api-go/app/init.go:45: undefined: mongodb in mongodb.MaxPool
api-go/app/init.go:45: cannot assign to mongodb.MaxPool
api-go/app/init.go:46: undefined: mongodb in mongodb.PATH
api-go/app/init.go:46: cannot assign to mongodb.PATH
api-go/app/init.go:47: undefined: mongodb in mongodb.DBNAME
api-go/app/init.go:47: cannot assign to mongodb.DBNAME
api-go/app/init.go:48: undefined: mongodb in mongodb.CheckAndInitServiceConnection

I used Mac Sierra. What's wrong with my application?

error on browser

Oscar Yuandinata
  • 1,025
  • 1
  • 13
  • 31
  • 1
    Do you have all your import properly made? For example do you have "log" in your imports ? – Majonsi Oct 18 '16 at 10:28
  • I'm new to Go development. In which file do you mean? In controllers, models? – Oscar Yuandinata Oct 18 '16 at 10:57
  • As I see your errors I think you should add in your file "init.go" this code `import ( "log" "github.com/revel/revel" “myapp/app/models/mongodb” ) ` This just under the first line of your init.go whitch contain "package" – Majonsi Oct 18 '16 at 11:58
  • I add your code. This time, all the errors disappear except `api-go/app/init.go:45: undefined: revel.LoadConfig` – Oscar Yuandinata Oct 19 '16 at 03:50

3 Answers3

1

Comment this lines:

//Config, err := revel.LoadConfig("app.conf")
//if err != nil || Config == nil {
//        log.Fatalf("%+v",err)
//}
0

As I see your errors I think you should add in your file "init.go" this code

     import ( 
        "log"
        "github.com/revel/revel" 
        “myapp/app/models/mongodb”
      ) 

This just under the first line of your init.go whitch contain "package"

Next in your code you have to replace:

   revel.LoadConfig("app.conf")

by

   revel.config.LoadContext("app.conf",ConfPaths)

where confPaths is the string path to your conf file. In your case it can be:

    ConfPaths := "conf/"

or

    ConfPaths := ""
Majonsi
  • 384
  • 1
  • 4
  • 17
0

That works for me. Imports:

import (
    "github.com/melkor217/myapp/app/models/mongodb"
    "github.com/revel/config"
    "github.com/revel/revel"
    "log"
)

Load config:

Config, err := config.LoadContext("app.conf", revel.ConfPaths)