예제 #1
0
파일: httptest.go 프로젝트: Centny/Cny4go
func NewMuxServer() *Server {
	sb := routing.NewSrvSessionBuilder("", "/", "tsrv", 60000, 200)
	mux := routing.NewSessionMux("", sb)
	srv := &Server{Mux: mux}
	srv.S = httptest.NewServer(mux)
	srv.URL = srv.S.URL
	return srv
}
예제 #2
0
파일: handle.go 프로젝트: Centny/igtest_ex
func NewSrvMux(pre string) *routing.SessionMux {
	sb := routing.NewSrvSessionBuilder("", "/", "ckey", 600000, 1000)
	mux := routing.NewSessionMux(pre, sb)
	mux.HFunc("^/adda", pkga.AddA)
	mux.HFunc("^/dela", pkga.DelA)
	mux.HFunc("^/addb", pkgb.AddB)
	mux.HFunc("^/getb", pkgb.GetB)
	return mux
}
예제 #3
0
파일: example.go 프로젝트: Centny/Cny4go
func main() {
	db, err := sql.Open("mysql", test.TDbCon)
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()
	sb := routing.NewSrvSessionBuilder("", "/", "example", 60*60*1000, 10000)
	mux := routing.NewSessionMux("/example", sb)
	mux.HFilterFunc("^.*$", func(hs *routing.HTTPSession) routing.HResult {
		log.D("filt 001")
		return routing.HRES_CONTINUE
	})
	//http://localhost:8080/example/ok
	mux.HFunc("^/ok(\\?.*)?$", func(hs *routing.HTTPSession) routing.HResult {
		hs.MsgRes("OK")
		return routing.HRES_RETURN
	})
	//http://localhost:8080/example/data
	mux.HFunc("^/data(\\?.*)?$", func(hs *routing.HTTPSession) routing.HResult {
		var tid int64
		var name string
		err := hs.ValidRVal(`//valid the argument
			tid,R|I,R:0,tid is error;
			name,R|S,L:0,name is empty;
			`, &tid, &name)
		if err != nil {
			return hs.MsgResE(1, err.Error())
		}
		name = "%" + name + "%"
		var ts []TSt
		err = dbutil.DbQueryS(db, &ts, "select * from ttable where tid>? and tname like ?", tid, name)
		if err != nil {
			return hs.MsgResE(1, err.Error())
		}
		return hs.MsgRes(ts)
	})
	mux.HFunc("^/mdata(\\?.*)?$", func(hs *routing.HTTPSession) routing.HResult {
		hs.W.Write([]byte("some data\n"))
		return routing.HRES_RETURN
	})
	s := http.Server{Addr: ":8080", Handler: mux}
	err = s.ListenAndServe()
	if err != nil {
		fmt.Println(err)
	}
}
예제 #4
0
파일: httptest.go 프로젝트: Centny/Cny4go
func NewServer2(h routing.Handler) *Server {
	sb := routing.NewSrvSessionBuilder("", "/", "tsrv", 60000, 200)
	mux := routing.NewSessionMux("", sb)
	mux.H("^.*$", h)
	return NewMuxServer2(mux)
}