-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.go
60 lines (47 loc) · 1.22 KB
/
server.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package commands
import (
"net/http"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
type Server struct{}
// GetRequiredFlags returns the server required flags.
func (*Server) GetRequiredFlags() []string {
return []string{}
}
// ServeHTTP handle any request.
func (*Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
_, _ = rw.Write([]byte("Hello"))
}
// SetFlags set the available flags.
func (*Server) SetFlags(f *pflag.FlagSet) {}
// GetArgs return the args.
func (*Server) GetArgs() cobra.PositionalArgs {
return nil
}
// GetDescription returns the command description.
func (*Server) GetDescription() string {
return "Run the rudy web server"
}
// GetLongDescription returns the command long description.
func (*Server) GetLongDescription() string {
return "Run the rudy web server"
}
// Info returns the command name.
func (*Server) Info() string {
return "server"
}
// Run executes the script associated to the command.
func (s *Server) Run() RunCmd {
return func(_ *cobra.Command, _ []string) {
_ = http.ListenAndServe(":8081", s)
}
}
func newServer() command {
return &Server{}
}
var (
_ command = (*Server)(nil)
_ commandInstanciator = newServer
)