MCPcopy Index your code
hub / github.com/koding/kite / main

Function main

examples/math/math-kite/math.go:12–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func main() {
13 flag.Parse()
14
15 // Create a kite.
16 k := kite.New("math", "1.0.0")
17
18 // Add pre handler method.
19 k.PreHandleFunc(func(r *kite.Request) (interface{}, error) {
20 fmt.Println("\nThis pre handler is executed before the method is executed")
21 resp := "hello from pre handler!"
22
23 // let us return an hello to base square method!
24 r.Context = context.WithValue(r.Context, "response", resp)
25 return resp, nil
26 })
27
28 // Add post handler method.
29 k.PostHandleFunc(func(r *kite.Request) (interface{}, error) {
30 fmt.Println("This post handler is executed after the method is executed")
31
32 // Pass the response from the previous square method back to the
33 // client, this is imporant if you use post handler.
34 return r.Context.Value("response").(string), nil
35 })
36
37 // Add our handler method, authentication is disabled for this example.
38 k.HandleFunc("square", Square).DisableAuthentication().PreHandleFunc(func(r *kite.Request) (interface{}, error) {
39 fmt.Println("This pre handler is only valid for this individual method")
40 return nil, nil
41 })
42
43 // Attach to a server and run it.
44 k.Config.IP = math.Host.IP()
45 k.Config.Port = math.Host.Port()
46 k.Run()
47}
48
49func Square(r *kite.Request) (interface{}, error) {
50 // Unmarshal method arguments.

Callers

nothing calls this directly

Calls 8

ValueMethod · 0.80
DisableAuthenticationMethod · 0.80
HandleFuncMethod · 0.80
IPMethod · 0.80
PreHandleFuncMethod · 0.45
PostHandleFuncMethod · 0.45
PortMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected