forked from sundowndev/phoneinfoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
44 lines (34 loc) · 898 Bytes
/
serve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"log"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
api "gopkg.in/sundowndev/phoneinfoga.v2/api"
)
var httpPort int
var disableClient bool
func init() {
// Register command
rootCmd.AddCommand(serveCmd)
// Register flags
serveCmd.PersistentFlags().IntVarP(&httpPort, "port", "p", 5000, "HTTP port")
serveCmd.PersistentFlags().BoolVar(&disableClient, "no-client", false, "Disable web client (REST API only)")
}
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Serve web client",
Run: func(cmd *cobra.Command, args []string) {
router := gin.Default()
api.Serve(router, disableClient)
httpPort := ":" + strconv.Itoa(httpPort)
srv := &http.Server{
Addr: httpPort,
Handler: router,
}
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)
}
},
}