Skip to content

Commit

Permalink
Merge pull request #302 from RockJohnson503/master
Browse files Browse the repository at this point in the history
fixed web listen address
  • Loading branch information
Jrohy authored Oct 15, 2020
2 parents f5db28f + 2dbd80d commit e7c7f4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

var (
host string
port int
ssl bool
)
Expand All @@ -15,11 +16,12 @@ var webCmd = &cobra.Command{
Use: "web",
Short: "以web方式启动",
Run: func(cmd *cobra.Command, args []string) {
web.Start(port, ssl)
web.Start(host, port, ssl)
},
}

func init() {
webCmd.Flags().StringVarP(&host, "host", "", "0.0.0.0", "web服务监听地址")
webCmd.Flags().IntVarP(&port, "port", "p", 80, "web服务启动端口")
webCmd.Flags().BoolVarP(&ssl, "ssl", "", false, "web服务是否以https方式运行")
rootCmd.AddCommand(webCmd)
Expand Down
6 changes: 3 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func staticRouter(router *gin.Engine) {
}

// Start web启动入口
func Start(port int, isSSL bool) {
func Start(host string, port int, isSSL bool) {
router := gin.Default()
router.Use(gzip.Gzip(gzip.DefaultCompression))
staticRouter(router)
Expand All @@ -141,8 +141,8 @@ func Start(port int, isSSL bool) {
if isSSL {
config := core.Load("")
ssl := &config.SSl
router.RunTLS(fmt.Sprintf(":%d", port), ssl.Cert, ssl.Key)
router.RunTLS(fmt.Sprintf("%s:%d", host, port), ssl.Cert, ssl.Key)
} else {
router.Run(fmt.Sprintf(":%d", port))
router.Run(fmt.Sprintf("%s:%d", host, port))
}
}

0 comments on commit e7c7f4c

Please sign in to comment.