示例#1
0
文件: web.go 项目: marswang/nosurf
func main() {
	server := web.NewServer()
	server.Get("/", myHandler)
	server.Post("/", myHandler)

	http.ListenAndServe(":8000", nosurf.New(server))
}
示例#2
0
文件: wsapi.go 项目: jjdevbiz/factomd
func Start(state interfaces.IState) {
	var server *web.Server

	if Servers == nil {
		Servers = make(map[int]*web.Server)
	}

	if Servers[state.GetPort()] == nil {
		server = web.NewServer()
		Servers[state.GetPort()] = server
		server.Env["state"] = state

		server.Post("/v1/factoid-submit/?", HandleFactoidSubmit)
		server.Post("/v1/commit-chain/?", HandleCommitChain)
		server.Post("/v1/reveal-chain/?", HandleRevealChain)
		server.Post("/v1/commit-entry/?", HandleCommitEntry)
		server.Post("/v1/reveal-entry/?", HandleRevealEntry)
		server.Get("/v1/directory-block-head/?", HandleDirectoryBlockHead)
		server.Get("/v1/get-raw-data/([^/]+)", HandleGetRaw)
		server.Get("/v1/directory-block-by-keymr/([^/]+)", HandleDirectoryBlock)
		server.Get("/v1/entry-block-by-keymr/([^/]+)", HandleEntryBlock)
		server.Get("/v1/entry-by-hash/([^/]+)", HandleEntry)
		server.Get("/v1/chain-head/([^/]+)", HandleChainHead)
		server.Get("/v1/entry-credit-balance/([^/]+)", HandleEntryCreditBalance)
		server.Get("/v1/factoid-balance/([^/]+)", HandleFactoidBalance)
		server.Get("/v1/factoid-get-fee/", HandleGetFee)

		log.Print("Starting server")
		go server.Run(fmt.Sprintf("localhost:%d", state.GetPort()))
	}

}
示例#3
0
func NewWebServer(webCfg *WebConfig, sessionService services.SessionService) framework.WebServer {

	sessionManager := NewSessionManager(webCfg, sessionService)
	_srv := _web.NewServer()
	_srv.Logger = log.New(ioutil.Discard, log.Prefix(), log.Flags())
	server := &webServer{config: webCfg, sessionManager: sessionManager, _srv: _srv}

	return server
}
示例#4
0
文件: s3_test.go 项目: jpoz/s3meta
func init() {
	FakeS3 = make(map[string]string)
	TestBucket = &Bucket{
		"localhost:7777",
		"/",
		"WhatEvenISComputerz",
		"ADogWalkedInToABarAndOrderADrinkJKHePoopedHesADog",
	}

	S3Server = web.NewServer()
	S3Server.Get("/(.*)", S3GetHandler)
	S3Server.Put("/(.*)", S3SetHandler)

	go S3Server.Run("0.0.0.0:7777")
}
示例#5
0
func Start() {
	server := web.NewServer()

	// Model
	model.Init(server)

	// View
	view.Init(server, templateRoot)

	// Static files (non-prod)
	if serveStaticFiles {
		helpers.ServeStatic("./static", server)
	}

	log.Printf("Now starting Todo App Server on port %d...", port)
	if useCGI {
		server.RunFcgi(fmt.Sprintf("0.0.0.0:%d", port))
	} else {
		server.Run(fmt.Sprintf("0.0.0.0:%d", port))
	}
}
示例#6
0
func main() {
	c, err := LoadConfig("./conf.yaml")
	if err != nil {
		fmt.Println("Error loading config file:", err)
	}
	web.Config.CookieSecret = c.CookieSecret

	//setup server and handlers
	server := web.NewServer()
	sm := NewSessionManager(c)
	te, err := NewThemeEngine()
	if err != nil {
		fmt.Println("Error creating theme engine:", err)
		return
	}
	controller := Controller{themeEngine: te, sessionManager: sm, articlesPerPage: c.ArticlesPerPage}
	controller.Init(c, server)
	te.Run()
	switch c.Protocol {
	case "https":
		//setup for https
		config := tls.Config{
			Time: nil,
		}

		config.Certificates = make([]tls.Certificate, 1)
		config.Certificates[0], err = tls.LoadX509KeyPair(c.Certfile, c.Keyfile)

		if err != nil {
			fmt.Println("error, could not load ssl cert and/or key")
			return
		}
		server.RunTLS(c.Address+":"+c.Port, &config)
	case "http":
		server.Run(c.Address + ":" + c.Port)
	case "fcgi":
		server.RunFcgi(c.Address + ":" + c.Port)

	}
}
示例#7
0
文件: wsapi.go 项目: Kalipsol/factomd
const (
	httpOK  = 200
	httpBad = 400
)

var (
	cfg             = util.ReadConfig().Wsapi
	portNumber      = cfg.PortNumber
	applicationName = cfg.ApplicationName
	dataStorePath   = "/tmp/store/seed/csv"
)

var _ = fmt.Println

var server = web.NewServer()

var (
	inMessageQ chan wire.FtmInternalMsg
	dbase      database.Db
)

func Start(db database.Db, inMsgQ chan wire.FtmInternalMsg) {
	factomapi.SetDB(db)
	dbase = db
	factomapi.SetInMsgQueue(inMsgQ)
	inMessageQ = inMsgQ

	wsLog.Debug("Setting Handlers")
	server.Post("/v1/commit-chain/?", handleCommitChain)
	server.Post("/v1/reveal-chain/?", handleRevealChain)
示例#8
0
func main() {

	globe := MakeGeodesic(1, 3)

	globeHandler := func(ctx *web.Context) {

		obj, err := json.Marshal(globe)
		check(err)
		ctx.ContentType("json")
		_, err = ctx.Write(obj)
		check(err)

	}

	clickHandler := func(ctx *web.Context) {

		u, err := strconv.Atoi(ctx.Params["u"])
		check(err)

		v, err := strconv.Atoi(ctx.Params["v"])
		check(err)

		fmt.Println(u, v)

		node := globe.U_Array[u][v]

		fmt.Println(node)

		var result []byte

		space := node.Space

		if node.Space == nil {
			space = &BoardSpace{PlayerID: 0, Armies: 0}
			node.Space = space
		}

		space.PlayerID = (space.PlayerID + 1) % 3

		result, err = json.Marshal(space)
		check(err)
		ctx.ContentType("json")
		_, err = ctx.Write([]byte(result))
		check(err)

	}

	authHandler := func(ctx *web.Context) {

		value, hasCookie := ctx.GetSecureCookie("user")

		fmt.Println(hasCookie, value)

	}

	server := web.NewServer()

	server.Config.CookieSecret = "todo~commissar165412399"

	//    Static    routers
	server.Get("/", gamePageHandler)
	server.Get("/(images/.*[.]png)", pngHandler)
	server.Get("/(scripts/.*[.]js)", scriptHandler)
	server.Get("/(shaders/.*[.]vert)", vertexShaderHandler)
	server.Get("/(shaders/.*[.]frag)", fragmentShaderHandler)

	//    Serve    globe    terrain
	server.Get("/globe", globeHandler)

	//    What    do    do    when    we    clicked    on    a    board    space
	server.Post("/click", clickHandler)
	server.Post("/auth", authHandler)

	server.Get("/echo", chatServer())
	server.Get("/action", actionServer(globe))

	server.Run(":8080")

}
示例#9
0
func main() {
	server := web.NewServer()
	server.Get("/echo", chatServer())
	server.Run(":8080")
}
示例#10
0
func init() {
	svr := web.NewServer()
	ExampleInitController(svr, path)
	go svr.Run(fmt.Sprintf("0.0.0.0:%d", port))
	<-time.After(10 * time.Millisecond)
}