-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.go
37 lines (31 loc) · 848 Bytes
/
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
//
// Copyright (c) 2017 Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package auth
import (
"fmt"
"net/http"
"github.com/go-zoo/bone"
"go.uber.org/zap"
)
// HTTPServer function
func httpServer() http.Handler {
mux := bone.New()
mux.Get("/status", http.HandlerFunc(getStatus))
mux.Get("/users", http.HandlerFunc(getAllUsers))
mux.Get("/users/:id", http.HandlerFunc(getUserByID))
mux.Post("/users", http.HandlerFunc(createUser))
mux.Delete("/users/:id", http.HandlerFunc(deleteUser))
mux.Post("/login", http.HandlerFunc(login))
mux.Get("/auth", http.HandlerFunc(authorize))
return mux
}
func StartHTTPServer(host string, port int, errChan chan error) {
go func() {
p := fmt.Sprintf("%s:%d", host, port)
logger.Info("Starting EdgeX Auth", zap.String("url", p))
errChan <- http.ListenAndServe(p, httpServer())
}()
}