-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
executable file
·132 lines (109 loc) · 2.39 KB
/
test.go
File metadata and controls
executable file
·132 lines (109 loc) · 2.39 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"net/http"
"io"
"os"
"fmt"
)
func main() {
//http.HandleFunc("/", home)
http.HandleFunc("/client", htmlServer)
http.ListenAndServe("192.168.0.110:9099", nil)
}
func home(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "home server!")
}
func htmlServer(w http.ResponseWriter, r *http.Request) {
wd, _ := os.Getwd()
wd = wd + "/client"
fmt.Println(wd)
http.StripPrefix("/client", http.FileServer(http.Dir(wd))).ServeHTTP(w, r)
}
/*
package foog
import(
"fmt"
"log"
"reflect"
"strings"
)
type IObject interface {
}
type handlerEntity struct {
object IObject
method reflect.Value
argType reflect.Type
argIsRaw bool
}
type handlerManager struct{
handlers map[string]*handlerEntity
}
var (
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
typeOfBytes = reflect.TypeOf(([]byte)(nil))
)
func isHandlerMethod(method reflect.Method) bool{
mt := method.Type
if mt.NumIn() != 3{
return false
}
return true
}
func (this *handlerManager)register(obj IObject){
t := reflect.TypeOf(obj)
v := reflect.ValueOf(obj)
name := reflect.Indirect(v).Type().Name()
if this.handlers == nil{
this.handlers = make(map[string]*handlerEntity)
}
for m := 0; m < t.NumMethod(); m++ {
method := t.Method(m)
mt := method.Type
mn := method.Name
if isHandlerMethod(method){
raw := false
if mt.In(2) == typeOfBytes {
raw = true
}
this.handlers[strings.ToLower(fmt.Sprintf("%s.%s", name, mn))] = &handlerEntity{
object: obj,
method: v.Method(m),
argType: mt.In(2),
argIsRaw: raw,
}
}else{
log.Printf("%s.%s register failed, argc=%d\n", name, mn, mt.NumIn())
}
}
}
func (this *handlerManager)dispatch(name string, sess *Session, data interface{}){
h, ok := this.handlers[strings.ToLower(name)]
if !ok {
log.Println("not found handle by", name)
return
}
defer func() {
if err := recover(); err != nil {
log.Println("dispatch error", name, err)
}
}()
var serialized bool
var argv reflect.Value
if !h.argIsRaw && sess.serializer != nil {
if bytes,ok := data.([]byte); ok{
argv = reflect.New(h.argType.Elem())
err := sess.serializer.Decode(bytes, argv.Interface())
if err != nil {
log.Println("deserialize error", err.Error())
return
}
serialized = true
}
}
if !serialized {
argv = reflect.ValueOf(data)
}
args := []reflect.Value{reflect.ValueOf(sess), argv}
h.method.Call(args)
}
*/