codegangsta / gin Goto Github PK
View Code? Open in Web Editor NEWLive reload utility for Go web servers
License: MIT License
Live reload utility for Go web servers
License: MIT License
Currently I parse all template files into a variable when the app launches, so any later made changes will not appear, tried using gin -t . -i
but the html changes don't seem to do anything. Any information would be great thanks.
I think the reason is the filepath.Walk
did not support that?
any workaround?
Hi,
Did you plan to add some nice looking HTML output to gin for errors/panics in proxy.go, instead of just the raw string?
Maybe something similar looking to revel could be done:
http://robfig.github.io/revel/img/Panic.png
?
For just build errors the error message parsing to get the filename and linenumber should be pretty simple.
Not sure about panics though.
If you don't have anything like this already planned, I could give it a try if you'd like?
hi all,
I had already understand the different ! so close this issue.
Actually , I am using codegangsta/gin for a while and like it.
Today when I browse something on github I find the project :
https://github.com/gin-gonic/gin
What is the different between the two projects?
Just a name duplication ?
thanks.
Gin was working perfectly since i got this message when i try to save file.
goroutine 1 [running]:
runtime.systemstack_switch()
/usr/local/go/src/runtime/asm_amd64.s:245 fp=0xc8200ad2b8 sp=0xc8200ad2b0
runtime.mallocgc(0xf0, 0x438dc0, 0x0, 0xc820000180)
/usr/local/go/src/cmd/compile/main.go:32 +0x395 fp=0xc8200adf40 sp=0xc8200ade68
runtime.main()
...
stack continue
Thanx
I just wanted to say that this principle is stupid and frustrating.
My use case for broadcasting messages:
gin
acknowledged the change and is now recompiling the serverI have a project I'd like to work on with a certain -tags configuration. The only way I can get this to work with gin is to modify all my files so that my custom tag is the default one.
Use graceful(https://github.com/stretchr/graceful), we can shutdown the application gracefully.
Gin kill the app in 3seconds(in lib/runner.go), while the connection is still living.
And, the lib/builder.go use go to build binary file, but if the old process is living, the build will fail.
So, I think gin can build the binary to a temp file, then use install instead of copy/mv to overwrite
the binary file. So that We can use gin to work gracefully with graceful.
Of course, install can only used in *nix...
I see that Gin has a special case for websockets. It would be super cool if something similar could be done for EventSource.
I think the Accept header in the request or Content-Type header in the response being set to "text/event-stream" would be a good identifier.
I have a webapp and I noticed that gin is not rebuilding the webapp when I change files that are not .go source files. If gin monitored for changes to other types of files, it would make my development workflow quicker. Thanks!
I'm new at Go, and I'm using your package to live reload the source.
I have seen 2 issues. The first one is after a few seconds, of running, files at pkg folder are created. After that happens, I'm no longer able to update the files, since the rebuild is never executed and the newer version of the files is not loaded.
The second issue is some times I see:
http: proxy error: EOF
And after that, the server stops working. I need to stop gin and run it again.
I had it working with golang 1.3.3 and now it stopped since I have upgraded to 1.4. I am not sure exactly what the issue is but I thought I would report it.
In terminal:
export PORT=3000
gin -h
[gin] listening on port 0
I'm running the sample negroni code you have listening to port 3000
doesn't seem to work.
hi, could it be possible to add support for watching other file extensions other than *.go?
i have for instance HTML templates that are read at application startup and i need to watch them too.
i have quick and dirty fix for it in scanChanges function but i was thinking about proper switch that would allow to specify file types to watch.
I will try to find some time to analyze gin code and make pull request.
But someone familiar with the code should be able to implement this must faster.
Here is some sample code to implement it.
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
s := <-c
log.Print("Got signal: ", s)
// KILL the application here!
os.Exit(1)
}()
Hi,
I started using gin
today, but it keeps invoking OSX firewall each time the app binary is recompiled (in /gin-bin).
Do you want the application “gin-bin” to accept incoming network connections?
I checked if proxy is trying to bind on 0.0.0.0, but thats not the case. So I don't know why is it invoking the firewall popups.
Maybe something like this:
func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {
start := time.Now()
err := builder.Build()
if err != nil {
buildError = err
logger.Println("ERROR! Build failed.")
fmt.Println(builder.Errors())
} else {
// print success only if there were errors before
if buildError != nil {
elapsed := float64(time.Since(start).Nanoseconds())
logger.Println(`Build Successful in ` + fmt.Sprintf(`%.2f`, elapsed/1000000.0) + ` ms`)
}
buildError = nil
if immediate {
runner.Run()
}
}
time.Sleep(100 * time.Millisecond)
}
I guet sporadic test-failures (with the same code) due to race conditions when reading the output of the started command. I had this problem before, I think if a process exits before you can read it's output, it get's lost because the pipe is closed.
Running gin -b /tmp/bla
creates a tmp/
directory on current path instead of creating bla binary on /tmp
directory
I'm considering using this with one of my projects but the project has a custom build script that needs to run, i.e. not simply go build
. Have you considered adding a flag for a custom build command to run as an alternative to go build
?
I'm using Vagrant, and it frequently has a lot of problems keeping the correct time. This means sometimes I modify a file at 16:16 when time.Now() keeps saying it's 16:12 (and it compiles the app all the time).
This could be easily fixed replacing in this line:
https://github.com/codegangsta/gin/blob/master/main.go#L161
the code:
startTime = time.Now()
by:
startTime = info.ModTime()
I think it doesn't change the functionality at all but it fixes problems when using different clocks.
I see this strange behavior when I run gin
in a docker container. After making a change, the app will start reloading continuously, often not stopping for 10, 20+ attempts. This does not occur when run in a local environment.
I thought I had a standard use-case when I wanted to go run
a specific .go file every time it or something in the $GOPATH (where its dependencies live) changes.
But the command gin -t "/go/src" x.go
fails with:
[gin] ERROR! Build failed.
can't load package: package .: no buildable Go source files in /go/src
Is there any way to watch $GOPATH from outside of it? (Or also watch items above the current directory)
I have an app that takes an argument to a config file. Is there already a way to pass it in that I have missed or could we add it somehow?
I'm using colorgo
for coloring the compile output, it would be nice if gin
support it too, for example with a certain flag -g
or --go-command
, for example:
gin -g /home/asd/Dropbox/go/bin/colorgo -i -b /tmp/test-build
When I run my Martini server through Gin, CPU usage goes through the roof - 85-100% on one core whilst sitting idle. If I run it without Gin, it's less than 1%.
This has only started happening very recently. Ordinarily I'd suspect my own application code as the culprit, but the fact that it runs fine without Gin would indicate otherwise.
Running on an Ubuntu 12.04 Vagrant box on a Ubuntu 14.10 host.
Using Sublime Text 3 to save a server.go
file fails to activate reload. Saving the same file using vi, nano or emacs correctly reloads the code. Not sure if this is an issue with Sublime Text, OS X, Go or Gin. My guess would be that Sublime Text uses some kind of non standard OS API call to save files.
Mac OS X 10.10.2
1.4.2
Sublime Text 3 Build 3065
Steps to reproduce:
gin
Sometims the executable is not on the correct directory (since gin require to be runned on current directory), it would be nice to have a flag for example:
--exec_cd ../../
to change directory before running
or --compile_cd bla/another-service/
to change directory before compiling
When trying to use the "--path" flag, I was seeing...
$ gin --path $GOPATH/src/github.com/kojustin/mycoolwebserver
[gin] listening on port 3000
2015/12/16 21:18:14 http: proxy error: dial tcp [::1]:3001: getsockopt: connection refused
Running gin directly in the working directory worked fine.
As discussed in #15, it would be great if gin can skip directories, so assets wouldn't get scanned.
Hi,
I'm using gin for a while and I saw you advice to use "github.com/namsral/flag" in README if we need to override options in our app.
I've got an "-port" option in my app. So I decided to use it.
export PORT=8001
go run myapp.go
That's ok, I can read 8001 port. I stop and do following commands:
Now, I've got "PORT" env var set to ":8001" and I launch gin like this:
gin -a 8001 -p 8000
When I GET 127.0.0.1:8000 I've the error:
http: proxy error: dial tcp 127.0.0.1:8001: connection refused
If I go back to standard "flag" package and I change my program to listen 8001 by default, that works... (I unset PORT env var)
Any idea ?
I think it would be nice to have a tagged release binary that users can come download instead of telling the user to go get to install.
I do like the .env
approach but cannot see how it should be used.
Can you @codegangsta provide a workflow example of using the .env file?
What is the current purpose of this file and how is it linked to gin env
?
thanks
Related to #44
be nice to watch a separate directory where template files are kept.
i wont just to now if we can auto-refrache the page web when we do changes to awer pages
Right now gin
only listens to .go
files, which requires me to restart the server to see changes to .html
files. It might be useful to be able to specify extra file extension to watch.
What is up with this? I'll save the file and go reload the page but it's the same old page. I have to go back to my editor and save one more time before the changes are actually reflected. This is not ideal and it's a deal-breaker, not only for me. I've noticed a lot of other developers complaining about this, too.
Why is this happening and how could I potentially fix it?
It would be nice if gin support full path for -b, for example: gin -b /tmp/out.bin
all we need is to modify inside func MainAction(c *cli.Context) {
//runner := gin.NewRunner(filepath.Join(wd, builder.Binary()), c.Args()...)
runpath := builder.Binary()
if runpath[0] != '/' {
runpath = filepath.Join(wd, runpath)
}
runner := gin.NewRunner(runpath, c.Args()...)
After some rebuild, the binary gin builds is invalid.
$ ./gin-bin
-bash: ./gin-bin: cannot execute binary file: Exec format error
Hey, thanks for making gin!
I'm having a little problem when importing local packages.. It complains with:
can't load package: /x/y/main.go:7:2: local import "./routes" in non-local package
Doesn't happen when i go run main.go
.. Any ideas on what i'm doing wrong?
Thanks!
Might be worth checking whether there's a go
binary in $PATH on startup. When setting up a new install recently, I encountered the following immense stacktrace when using a terminal with a misconfigured environment, where gin
was in $PATH
, but go
wasn't:
matt@o:~/go/src/github.com/dgryski/carbonzipper$ gin -- -d=1 -c /etc/carbonzipper.conf -stdout=true
[gin] listening on port 3000
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x8 pc=0x45517e]
goroutine 16 [running]:
runtime.panic(0x6e6bc0, 0x8d70d3)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
os.(*ProcessState).success(0x0, 0xc20802a230)
/usr/local/go/src/pkg/os/exec_posix.go:73 +0x1e
os.(*ProcessState).Success(0x0, 0x0)
/usr/local/go/src/pkg/os/doc.go:72 +0x27
github.com/codegangsta/gin/lib.(*builder).Build(0xc208022c60, 0x0, 0x0)
/home/matt/go/src/github.com/codegangsta/gin/lib/builder.go:51 +0x159
main.build(0x7f251429c960, 0xc208022c60, 0x7f251429c998, 0xc2080042a0, 0xc208018640)
/home/matt/go/src/github.com/codegangsta/gin/main.go:135 +0x36
main.MainAction(0xc20806c180)
/home/matt/go/src/github.com/codegangsta/gin/main.go:112 +0x70f
github.com/codegangsta/cli.(*App).Run(0xc20806c0c0, 0xc208004060, 0x6, 0x6, 0x0, 0x0)
/home/matt/go/src/github.com/codegangsta/cli/app.go:135 +0x99c
main.main()
/home/matt/go/src/github.com/codegangsta/gin/main.go:73 +0x32f
goroutine 19 [finalizer wait]:
runtime.park(0x415340, 0x8dbbb0, 0x8d9e49)
/usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x8dbbb0, 0x8d9e49)
/usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
/usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
/usr/local/go/src/pkg/runtime/proc.c:1445
goroutine 20 [syscall]:
os/signal.loop()
/usr/local/go/src/pkg/os/signal/signal_unix.go:21 +0x1e
created by os/signal.init·1
/usr/local/go/src/pkg/os/signal/signal_unix.go:27 +0x32
goroutine 21 [runnable]:
net/http.Serve(0x7f251429ca30, 0xc20803a030, 0x7f251429da88, 0xc208000d20, 0x7f251429ca30, 0xc20803a030)
/usr/local/go/src/pkg/net/http/server.go:1574
created by github.com/codegangsta/gin/lib.(*Proxy).Run
/home/matt/go/src/github.com/codegangsta/gin/lib/proxy.go:43 +0x25e
goroutine 22 [runnable]:
main.func·003()
/home/matt/go/src/github.com/codegangsta/gin/main.go:183
created by main.shutdown
/home/matt/go/src/github.com/codegangsta/gin/main.go:191 +0x15f
matt@o:~/go/src/github.com/dgryski/carbonzipper$ export PATH=$PATH:$HOME/git_tree/go/bin
matt@o:~/go/src/github.com/dgryski/carbonzipper$ which go
/home/matt/git_tree/go/bin/go
matt@o:~/go/src/github.com/dgryski/carbonzipper$ gin -- -d=1 -c /etc/carbonzipper.conf -stdout=true
[gin] listening on port 3000
It's pretty straightforward to ship a Go app using e.g. google/golang, but I'm not sure how to setup an environment that works with gin. Any ideas?
Purpose: reduce write on disk (/tmp is RAM)
Shell script
gin -i -b "/tmp/gin-bin" "go build test.go && ./tmp/gin-bin"
the output
2014/12/10 15:45:16 http: proxy error: dial tcp 127.0.0.1:3001: connection refused
It seems that the emacs flymake package works by creating go files prepended with flymak. These are saved as you type so it can report errors within emacs buy seem to be immediately deleted. When this happens, I get errors of the form:
[gin] ERROR! Build failed.
# ctxl/l
open l/flymake_userhttp.go: No such file or directory
gin never seems to recover from this.
is there any way to set gin up so that it doesn't attempt to include files with regex such as flymake_*.go?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.