-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (53 loc) · 1.08 KB
/
main.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
61
62
63
64
65
package main
import (
"flag"
"log"
"net/http"
"github.com/aukbit/pluto"
"github.com/aukbit/pluto/reply"
"github.com/aukbit/pluto/server"
"github.com/aukbit/pluto/server/router"
)
var (
httpsPort string
)
func init() {
flag.StringVar(&httpsPort, "https_port", ":8443", "https port")
flag.Parse()
}
func main() {
// run frontend service
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
// Set server handlers
mux := router.New()
mux.GET("/", GetHandler)
// Create new http server
srv := server.New(server.Name("api"),
server.TLSConfig("server.crt", "private.key"),
server.Addr(httpsPort),
server.Mux(mux),
)
// Init service
s := pluto.New(
pluto.Name("web"),
pluto.Description("web server serving handlers with https/tls"),
pluto.Servers(srv),
pluto.HealthAddr(":9098"),
)
// Run service
if err := s.Run(); err != nil {
return err
}
return nil
}
type Message struct {
Message string `json:"message"`
}
func GetHandler(w http.ResponseWriter, r *http.Request) {
m := &Message{"Hello Gopher"}
reply.Json(w, r, http.StatusOK, m)
}