-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.go
44 lines (35 loc) · 808 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
38
39
40
41
42
43
44
package main
import (
"errors"
"fmt"
"github.com/dollarkillerx/light"
"github.com/dollarkillerx/light/server"
"log"
)
func main() {
ser := server.NewServer()
err := ser.RegisterName(&HelloWorld{}, "helloworld")
if err != nil {
log.Fatalln(err)
}
if err := ser.Run(server.UseTCP("0.0.0.0:8074"), server.SetAUTH(authFunc)); err != nil {
log.Fatalln(err)
}
}
func authFunc(ctx *light.Context, token string) error {
if token == "token" {
return nil
}
return errors.New("error 401")
}
type HelloWorld struct{}
type HelloWorldRequest struct {
Name string
}
type HelloWorldResponse struct {
Msg string
}
func (s *HelloWorld) HelloWorld(ctx *light.Context, req *HelloWorldRequest, resp *HelloWorldResponse) error {
resp.Msg = fmt.Sprintf("hello world by: %s", req.Name)
return nil
}