Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): Implements RunFd method #1609

Merged
merged 3 commits into from Nov 6, 2018

Conversation

yyoshiki41
Copy link
Contributor

@yyoshiki41 yyoshiki41 commented Oct 25, 2018

Renewed the pr #526.


I use gin http.Server under circus which is a socket manager.
I need to run http.Server through a file descriptor, so implemented RunFd method.

When using other socket managers (e.g. einhorn), maybe work well.

Usage

package main

import (
    "flag"
    "github.com/yyoshiki41/gin"
)

var (
    fd = flag.Int("fd", -1, "")
)

func main() {
    flag.Parse()

    r := gin.Default()
    // Ping test
    r.GET("/ping", func(c *gin.Context) {
        c.String(200, "pong")
    })
    // Method arg is the file descriptor number(int).
    r.RunFd(*fd)
}

and, circus.ini example is below.

[circus]
statsd = 1

[watcher:webapp]
cmd = ./main -fd $(circus.sockets.web)
numprocesses = 1
use_sockets = True

[socket:web]
host = 127.0.0.1
port = 8080

Demo

$ circusd circus.ini
2016-02-03 11:07:13 circus[46347] [INFO] Starting master on pid 46347
2016-02-03 11:07:13 circus[46347] [INFO] sockets started
2016-02-03 11:07:13 circus[46347] [INFO] Arbiter now waiting for commands
2016-02-03 11:07:13 circus[46347] [INFO] webapp started
2016-02-03 11:07:13 circus[46347] [INFO] circusd-stats started
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /ping                     --> main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on fd@5
2016-02-03 11:07:13 circus[46354] [INFO] Starting the stats streamer
# Ping test
$ curl localhost:8080/ping
pong

# Other terminal
[GIN] 2016/02/03 - 11:08:11 | 200 |    2.571629ms | 127.0.0.1 |   GET     /ping

thx ☀️


This change is Reviewable

@codecov
Copy link

codecov bot commented Oct 25, 2018

Codecov Report

Merging #1609 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1609      +/-   ##
==========================================
+ Coverage   99.28%   99.28%   +<.01%     
==========================================
  Files          40       40              
  Lines        1948     1958      +10     
==========================================
+ Hits         1934     1944      +10     
  Misses         10       10              
  Partials        4        4
Impacted Files Coverage Δ
gin.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cb390f...995fc82. Read the comment docs.

@yyoshiki41 yyoshiki41 mentioned this pull request Oct 25, 2018
@appleboy appleboy added this to the 1.4 milestone Nov 1, 2018
@thinkerou thinkerou merged commit 66b47a8 into gin-gonic:master Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants