-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.go
42 lines (35 loc) · 797 Bytes
/
demo.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
package pluginDemo
import (
"context"
"fmt"
"net/http"
)
type Config struct {
//...
Info string `json:"info,omitempty"`
}
func CreateConfig() *Config {
fmt.Println("Call CreateConfig()........")
return &Config{}
}
type Demo struct {
next http.Handler
name string
//...
}
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
//...
fmt.Println("Call New()........")
fmt.Printf("the name is: %s\n", name)
fmt.Printf("the content of info in configuration is: %s\n", config.Info)
return &Demo{
next: next,
name: name,
}, nil
}
func (demo *Demo) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
//...
fmt.Println("Call ServeHTTP()........")
fmt.Printf("url is: %s\n", req.URL.String())
demo.next.ServeHTTP(rw, req)
}