forked from st3v/go-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
38 lines (31 loc) · 745 Bytes
/
router.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
package main
import (
"net"
"net/http"
"github.com/micro/go-config"
"github.com/micro/go-config/source/file"
"github.com/micro/go-log"
"github.com/micro/go-plugins/micro/router"
)
func main() {
// Create listener
l, err := net.Listen("tcp", "localhost:10001")
if err != nil {
log.Fatal(err)
}
defer l.Close()
// Create Config Source
f := file.NewSource(file.WithPath("routes.json"))
conf := config.NewConfig(config.WithSource(f))
// Create Router
r := router.NewRouter(router.Config(conf))
// Setup Handler
wr := r.Handler()
h := wr(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not found", 404)
}))
// Start Server
if err := http.Serve(l, h); err != nil {
log.Fatal(err)
}
}