-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (43 loc) · 1.05 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
package main
import (
"log"
"net/http"
"os"
"golang.org/x/net/context"
"github.com/go-elm/account/auth"
authsvc "github.com/go-elm/account/auth/service"
"github.com/go-elm/account/user"
"github.com/go-elm/account/user/datastore/inmem"
kitlog "github.com/go-kit/kit/log"
)
func main() {
ctx := context.Background()
logger := kitlog.NewLogfmtLogger(os.Stdout)
logger.Log("msg", "hello")
defer logger.Log("msg", "goodbye")
userStore := inmem.New()
createFakeAdmin(userStore)
var session auth.Session
{
session = authsvc.New(userStore)
}
var authEndpoints authsvc.Endpoints
{
authEndpoints.Login = authsvc.MakeLoginEndpoint(session)
}
loginHandler := authsvc.MakeHTTPHandler(ctx, authEndpoints, logger)
mux := http.NewServeMux()
mux.Handle("/login", loginHandler)
mux.Handle("/", http.FileServer(http.Dir(".")))
log.Fatal(http.ListenAndServe(":8000", mux))
}
func createFakeAdmin(ds user.Datastore) {
user := user.User{
Username: "groob",
Password: []byte("secret"),
}
_, err := ds.Create(user)
if err != nil {
panic(err)
}
}