ericmdantas / generator-ng-fullstack

Client, server or fullstack - it's up to you. ng-fullstack gives you the best of the latest.
MIT License
704 stars 103 forks source link

GoLang error #133

Closed quanganh206 closed 8 years ago

quanganh206 commented 8 years ago

Hi,

I try to run golang server, client ng2 server return error like that. May I have your help with it.

Running at :3333
2016/04/30 15:19:06 http: panic serving 127.0.0.1:55841: runtime error: invalid memory address or nil pointer dereference
goroutine 5 [running]:
net/http.(*conn).serve.func1(0xc82007e400)
    /usr/local/go/src/net/http/server.go:1389 +0xc1
panic(0x407200, 0xc82000a0d0)
    /usr/local/go/src/runtime/panic.go:443 +0x4e9
github.com/labstack/echo/middleware.StaticWithConfig.func1.1(0xb05b98, 0xc8200821b0, 0x0, 0x0)
    /Users/anhlq/work/src/github.com/labstack/echo/middleware/static.go:109 +0xba8
github.com/labstack/echo.(*Echo).ServeHTTP.func1(0xb05b98, 0xc8200821b0, 0x0, 0x0)
    /Users/anhlq/work/src/github.com/labstack/echo/echo.go:542 +0x210
github.com/labstack/echo/middleware.RemoveTrailingSlashWithConfig.func1.1(0xb05b98, 0xc8200821b0, 0x0, 0x0)
    /Users/anhlq/work/src/github.com/labstack/echo/middleware/slash.go:80 +0x182
github.com/labstack/echo.(*Echo).ServeHTTP(0xc8200b6820, 0xb05a90, 0xc820015380, 0xb05b38, 0xc820012820)
    /Users/anhlq/work/src/github.com/labstack/echo/echo.go:551 +0x259
github.com/labstack/echo/engine/standard.(*Server).ServeHTTP(0xc82007e300, 0xb05968, 0xc820065520, 0xc8200f0000)
    /Users/anhlq/work/src/github.com/labstack/echo/engine/standard/server.go:137 +0x67c
net/http.serverHandler.ServeHTTP(0xc82007e200, 0xb05968, 0xc820065520, 0xc8200f0000)
    /usr/local/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc82007e400)
    /usr/local/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2137 +0x44e
ericmdantas commented 8 years ago

Hello, @quanganh206.

Can I see your server.go file?

quanganh206 commented 8 years ago

Hi @ericmdantas

You mean main.go, I try go run main.go after go get.

package main

import (
    "fmt"
    "github.com/quanganh206/testgo/server/routes"
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/fasthttp"
)

const port string = ":3333"

func main() {
    fmt.Printf("Running at %v\n", port)
    e := echo.New()
    routes.Init(e)
    e.Run(fasthttp.New(port))
}
ericmdantas commented 8 years ago

Right, yeah main.go.

That's an odd error and seems to be related to either echo or fasthttp.

Do you have the whole project in github or somewhere I can clone?

quanganh206 commented 8 years ago

Hi @ericmdantas,

Please find it here: https://github.com/quanganh206/testgo

My environment:

ericmdantas commented 8 years ago

Ok, I'll be able to try it out later today.

ericmdantas commented 8 years ago

Right, so I managed to simulate it, I'll let people from echo know. Thanks!

ericmdantas commented 8 years ago

The problem seems to be related to the static middleware, the simplest example fails with the error you're reporting.

Here's a repo with the same error: https://github.com/ericmdantas/echo-static

ericmdantas commented 8 years ago

Also, if you access http://localhost:3333/api/todos you'll get the list of todos just fine. The problem is just the static middleware.

ericmdantas commented 8 years ago

The problem is in the following lines:

    e.Use(middleware.Static(""))
    e.Use(middleware.Static(dev))

In https://github.com/ericmdantas/generator-ng-fullstack/blob/master/app/templates/server_go/common/static/static.go#L13.

But this was supposed to work, there's been an update and it was problem broken.

quanganh206 commented 8 years ago

Thanks!

ericmdantas commented 8 years ago

Just opened an issue on echo: https://github.com/labstack/echo/issues/496

Edit: typo

ericmdantas commented 8 years ago

Should be fixed now, just go to the server folder and run:

go get -u ./... github.com/labstack/echo.

Let me know how it goes.

quanganh206 commented 8 years ago

Thanks for your help!

I try to test it work (not product old errors), but when running with client, client only say Not Found with localhost:3000. I retest with NodeJS, everything working okay. And check api in localhost:3333 it working okay as you said. But it's still not working.

ericmdantas commented 8 years ago

Are you running it with gulp?

quanganh206 commented 8 years ago

Yes, I run go run main.go to start server.

After that I run gulp for client but it product not found as I mention.

ericmdantas commented 8 years ago

That's weird.

Let me take another look.

ericmdantas commented 8 years ago

It's working fine here, @quanganh206. I used your repo to try to reproduce, and was able to serve the app just fine.

Is there anything you modified on your end and didn't commit there?

Also, could you please share the log in your dev tools, in Chrome, for example?

quanganh206 commented 8 years ago

I meet that, the same repos testgo as you did.

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/favicon.ico 
Running Ginger Widget  version 0.1.0.598  gingerEditor.min.js:21 
Failed to load resource: the server responded with a status of 404 (Not Found)  http://localhost:3000/ 
ericmdantas commented 8 years ago

What is this ginger widget?

quanganh206 commented 8 years ago

I use this for English Grammar :) http://www.gingersoftware.com/

ericmdantas commented 8 years ago

Oh, ok. Not related then.

I might be able to take a closer look later today. Please, update your repo with your modifications, if you do any.

quanganh206 commented 8 years ago

Yes, thanks @ericmdantas, wait for you.

ericmdantas commented 8 years ago

Can you please clone this repo https://github.com/ericmdantas/echo-static and see if it works?

If should serve static and have an api in /api. It's the smallest reproducible scenario for your case, I guess.

quanganh206 commented 8 years ago

Hi @ericmdantas, let's me try this and feedback with you.