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

support run HTTP server with specific net.Listener #2023

Merged
merged 2 commits into from Sep 30, 2019

Conversation

Zheaoli
Copy link
Contributor

@Zheaoli Zheaoli commented Aug 18, 2019

We have to use Gin with a special listener in some situations.

For example, if we want to upgrade Gin server graceful, we may use the third party lib to support this feature such as tableflip

Here's some example code

upg, err := tableflip.New(tableflip.Options{})
if err != nil {
	panic(err)
}
defer upg.Stop()

go func() {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGHUP)
	for range sig {
		err := upg.Upgrade()
		if err != nil {
			log.Println("Upgrade failed:", err)
			continue
		}

		log.Println("Upgrade succeeded")
	}
}()

ln, err := upg.Fds.Listen("tcp", "localhost:8080")
if err != nil {
	log.Fatalln("Can't listen:", err)
}

go router.RunListener(ln)

if err := upg.Ready(); err != nil {
	panic(err)
}
<-upg.Exit()

time.AfterFunc(30*time.Second, func() {
	os.Exit(1)
})

_ = server.Shutdown(context.Background())

@codecov
Copy link

codecov bot commented Aug 18, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2023      +/-   ##
==========================================
+ Coverage   98.92%   98.92%   +<.01%     
==========================================
  Files          40       40              
  Lines        2224     2229       +5     
==========================================
+ Hits         2200     2205       +5     
  Misses         12       12              
  Partials       12       12
Impacted Files Coverage Δ
gin.go 99.13% <100%> (+0.01%) ⬆️

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 9b9f4fa...3c47bed. Read the comment docs.

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Sep 15, 2019

is this PR work?

appleboy
appleboy previously approved these changes Sep 24, 2019
@appleboy
Copy link
Member

@thinkerou Need your review.

gin.go Outdated Show resolved Hide resolved
@Zheaoli
Copy link
Contributor Author

Zheaoli commented Sep 25, 2019

I have already update the debug info.

Copy link
Member

@thinkerou thinkerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thinkerou thinkerou merged commit 79840bc into gin-gonic:master Sep 30, 2019
ThomasObenaus pushed a commit to ThomasObenaus/gin that referenced this pull request Feb 19, 2020
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