Live reload utility for Go web servers

gin wercker status

gin is a simple command line utility for live-reloading Go web applications. Just run gin in your app directory and your web app will be served with gin as a proxy. gin will automatically recompile your code when it detects a change. Your app will be restarted the next time it receives an HTTP request.

gin adheres to the "silence is golden" principle, so it will only complain if there was a compiler error or if you succesfully compile after an error.

Installation

Assuming you have a working Go environment and GOPATH/bin is in your PATH, gin is a breeze to install:

go get github.com/codegangsta/gin

Then verify that gin was installed correctly:

gin -h

Basic usage

gin run main.go

Options

   --laddr value, -l value       listening address for the proxy server
   --port value, -p value        port for the proxy server (default: 3000)
   --appPort value, -a value     port for the Go web server (default: 3001)
   --bin value, -b value         name of generated binary file (default: "gin-bin")
   --path value, -t value        Path to watch files from (default: ".")
   --build value, -d value       Path to build files from (defaults to same value as --path)
   --excludeDir value, -x value  Relative directories to exclude
   --immediate, -i               run the server immediately after it's built
   --all                         reloads whenever any file changes, as opposed to reloading only on .go file change
   --godep, -g                   use godep when building
   --buildArgs value             Additional go build arguments
   --certFile value              TLS Certificate
   --keyFile value               TLS Certificate Key
   --logPrefix value             Setup custom log prefix
   --notifications               enable desktop notifications
   --help, -h                    show help
   --version, -v                 print the version

Supporting Gin in Your Web app

gin assumes that your web app binds itself to the PORT environment variable so it can properly proxy requests to your app. Web frameworks like Martini do this out of the box.

Using flags?

When you normally start your server with flags if you want to override any of them when running gin we suggest you instead use github.com/namsral/flag as explained in this post

Comments
  • Sporadic error:  http: proxy error: dial tcp 127.0.0.1:3001: connection refused

    Sporadic error: http: proxy error: dial tcp 127.0.0.1:3001: connection refused

    I am getting this error sometimes. I have to quit and restart gin (sometimes multiple times). Any idea on how to debug this? I guess in some condition gin thinks there is a backend process running but it isn't?

  • Extremely high CPU usage

    Extremely high CPU usage

    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.

  • Added push notifications when a build fails or finished

    Added push notifications when a build fails or finished

    It's a lot nicer getting immediate feedback via a push notification when a build finishes. This way you never really need to look at the terminal other than for logs.

  • gin osx firewall issue

    gin osx firewall issue

    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.

  • Added flag for verbose mode and custom file extensions

    Added flag for verbose mode and custom file extensions

    Hi there!

    I had the need to have Gin to trigger rebuild based on files other than .go (.ace templates for example), so I added this feature, hoping it'll be useful for others. OK, actually a reload of the server would suffice (Ace caches parsed templates), but this is handy anyway...

    This is my first PR (to any public project), but be merciless!

  • Allow watching multiple paths for changes

    Allow watching multiple paths for changes

    Hi, this change allows gin to watch multiple paths for changes.

    The PR also adds a new parameter (--cwd or -d) to specify where to build from. It defaults to the current directory which is how it worked before the change.

    The parameter --path now can include multiple paths in the format of that PATH variable (i.e. a list of paths separated by os.PathListSeparator)

    Please consider merging. Thanks, -rst.

  • Recompiling stopped working with golang v1.4

    Recompiling stopped working with golang v1.4

    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.

  • Add an option to immediately run the web server after it's built

    Add an option to immediately run the web server after it's built

    Hi,

    To address #17, which in my case is caused by the slow bootstrapping of the web server, I come up with this work-around to run the web server immediately after it's built thus minimizing the effect of delayed port binding.

    This, however, will not solve the race condition when the proxy tries to connect to a still-bootstrapping server, which is far more complicated... it only tries to start the application as early as possible so that hopefully when we switch to browser the server is already accepting connection.

  • Broken build

    Broken build

    Attempting to install from the latest code fails:

    gibson@3e8c8777a5ec:~$ go version
    go version go1.15.9 linux/arm64
    gibson@3e8c8777a5ec:~$ go get -u github.com/codegangsta/gin
    # github.com/codegangsta/gin
    go/src/github.com/codegangsta/gin/main.go:40:13: cannot use MainAction (type func(*cli.Context)) as type cli.ActionFunc in assignment
    go/src/github.com/codegangsta/gin/main.go:42:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
    	cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
    go/src/github.com/codegangsta/gin/main.go:45:4: unknown field 'EnvVar' in struct literal of type cli.StringFlag
    go/src/github.com/codegangsta/gin/main.go:48:14: cannot use cli.IntFlag literal (type cli.IntFlag) as type cli.Flag in slice literal:
    	cli.IntFlag does not implement cli.Flag (Apply method has pointer receiver)
    go/src/github.com/codegangsta/gin/main.go:51:4: unknown field 'EnvVar' in struct literal of type cli.IntFlag
    go/src/github.com/codegangsta/gin/main.go:54:14: cannot use cli.IntFlag literal (type cli.IntFlag) as type cli.Flag in slice literal:
    	cli.IntFlag does not implement cli.Flag (Apply method has pointer receiver)
    go/src/github.com/codegangsta/gin/main.go:57:4: unknown field 'EnvVar' in struct literal of type cli.IntFlag
    go/src/github.com/codegangsta/gin/main.go:60:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
    	cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
    go/src/github.com/codegangsta/gin/main.go:63:4: unknown field 'EnvVar' in struct literal of type cli.StringFlag
    go/src/github.com/codegangsta/gin/main.go:69:4: unknown field 'EnvVar' in struct literal of type cli.StringFlag
    go/src/github.com/codegangsta/gin/main.go:69:4: too many errors
    

    However, installing my fork of the previous version works as expected (https://github.com/buu700/gin).

  • gokpg.in/urfave/cli.v1 unrecognized

    gokpg.in/urfave/cli.v1 unrecognized

    I am trying to go get gin in golang docker image, however, this happens when the step executes:

    Step 3 : RUN go get github.com/codegangsta/gin
     ---> Running in f48b4cab2994
    package gopkg.in/urfave/cli.v1: unrecognized import path "gopkg.in/urfave/cli.v1" (https fetch: Get https://gopkg.in/urfave/cli.v1?go-get=1: x509: certificate has expired or is not yet valid)
    ERROR: Service 'init' failed to build: The command '/bin/sh -c go get github.com/codegangsta/gin' returned a non-zero code: 1
    

    Any idea what could be wrong?

  • Build bin relative to the working directory

    Build bin relative to the working directory

    Prevents unknown bin location when the path flag is set. Before, the binary was getting placed in the path location and the runner was trying to execute from the working path without success.

  • Perhaps suggest go install command instead of go get

    Perhaps suggest go install command instead of go get

    I was having loads of problems getting the project setup with the way described in the README. I thought the issue might have been my environment variables but it turns out they are fine by default. I was able to run executables from there globally but I noticed that gin wasn't there.

    go install github.com/codegangsta/gin@latest
    

    Above command did the trick for me.

  • Updated README.md with new install command

    Updated README.md with new install command

    'go get' is no longer supported outside a module. To build and install a command, use 'go install' with a version, like 'go install example.com/cmd@latest'

    see https://github.com/golang/go/issues/40276

  • Config.Laddr default value localhost.

    Config.Laddr default value localhost.

    When creating a listener with an empty address, the listener will assume any interface (0.0.0.0). This will trigger firewall permissions to be granted every time a unique binary is generated. This can be problematic during tests as the binary has a unique name by default.

    Since this is a proxy for development sake. It is safe to assume if Config.Laddr is not provided we can use localhost to avoid the firewall module.

  • command.ProcessState could be nil

    command.ProcessState could be nil

    During a build error found on Linux, command.ProcessState can be nil

    // if command.ProcessState.Success() {
    if command.ProcessState != nil && command.ProcessState.Success() {
        b.errors = ""
    } else {
        b.errors = string(output)
    }
    
Related tags
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - ???? Get started - ?? Config sample - ?? Commands List - ?? Support and Suggestions

Jan 6, 2023
A small utility that aims to automate and simplify some tasks related to software release cycles.

Stork is a small utility that aims to automate and simplify some tasks related to software release cycles such as reading the current version from a f

Nov 9, 2022
Build and (re)start go web apps after saving/creating/deleting source files.

unmaintained Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web f

Jan 2, 2023
Live reload for Go web development

livedev livedev is a development proxy server for golang that allows live reloading. It supports multiple server configuration. It uses the request's

Jun 17, 2022
☁️ Live reload for Go apps
☁️ Live reload for Go apps

Air ☁️ Live reload for Go apps Motivation When I get started with developing websites in Go and gin framework, it's a pity that gin lacks live-reloadi

Jan 1, 2023
Ambiente com Docker de "live-reload" para aplicações Go

Ambiente Go Um ambiente de "live reload", onde as alterações no código são observadas e re-executadas automaticamente, com Docker e Docker Compose. O

Jun 17, 2022
🔎 gowatch Live reload for go apps.

Watch ?? gowatch Live reload for go apps Motivation I had no app to live reload my Go programs. Usage Install go install github.com/gelfand/gowatch ◆

Dec 29, 2021
A live streaming tool more suitable for non-graphical servers

KPlayer KPlayer可以帮助你快速的在服务器上进行视频资源的循环直播推流。

Jan 2, 2023
Web app utility to get server list data from Minecraft servers.

Ping Web app utility to get server list data from Minecraft servers. Avalible at https://ping.turtley12.dev/app, Running yourself Before compiling and

Dec 21, 2021
Reload a specified go program automatically by monitoring a directory.

gowatcher A bash script to automatically reload a go program when .go or .html files change in the monitored directory. It uses inotify. Installation

Jul 7, 2020
Reload Go code in a running process at function/method level granularity

got reload? Function/method-level stateful hot reloading for Go! Status Very much work in progress.

Nov 9, 2022
Sidecar to watch a config folder and reload a process when it changes

A small (3MB uncompressed docker image), efficient (via inotify) sidecar to trigger application reloads when configuration changes.

Dec 29, 2022
A local server with real-time reload function designed for static website preview or development

中文 | English ?? 介绍 reserver 是一款为静态网站预览或开发设计的具有实时重新加载功能的本地服务器。 其主要运用场景为: 单页应用的预览(例如Vue编译之后的项目不可以直接通过file://协议进行访问) 具有ajax请求的页面(因浏览器安全限制,默认禁止file://协议进行

Aug 23, 2022
GCP Cloud Functions ready to Go starter with hot reload 🔥

GCP Cloud Functions - Go Starter Features: funcFramework already set up - ready for local development and testing. Hot Reload ready-to-go thanks to th

Dec 16, 2021
Golang http&grpc server for gracefully shutdown like nginx -s reload

supervisor Golang http & grpc server for gracefully shutdown like nginx -s reload if you want a server which would be restarted without stopping servi

Jan 8, 2022
This is a hot reload tooling for go

hotpocket This is a hot reload tooling for go Usage First need to have a json file in the root of your project. Name it as a hotpocket.json. It Should

Jul 17, 2022
Nov 9, 2022
Instant, disposable, single-binary web based live chat server. Go + VueJS.
Instant, disposable, single-binary web based live chat server. Go + VueJS.

Niltalk Niltalk is a web based disposable chat server. It allows users to create password protected disposable, ephemeral chatrooms and invite peers t

Jan 4, 2023
Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump.
Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump.

Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump. Some of its features include: Unde

Feb 26, 2022