当前位置: 首页>>代码示例>>Golang>>正文


Golang goji.Serve函数代码示例

本文整理汇总了Golang中github.com/zenazn/goji.Serve函数的典型用法代码示例。如果您正苦于以下问题:Golang Serve函数的具体用法?Golang Serve怎么用?Golang Serve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Serve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.StringVar(&repoPrefix, "prefix", "", "The repo name prefix required in order to build.")
	flag.Parse()

	if repoPrefix == "" {
		log.Fatal("Specify a prefix to look for in the repo names with -prefix='name'")
	}

	if f, err := os.Stat(sourceBase); f == nil || os.IsNotExist(err) {
		log.Fatalf("The -src folder, %s, doesn't exist.", sourceBase)
	}

	if f, err := os.Stat(destBase); f == nil || os.IsNotExist(err) {
		log.Fatalf("The -dest folder, %s, doesn't exist.", destBase)
	}

	if dbConnString != "" {
		InitDatabase()
	}

	goji.Get("/", buildsIndexHandler)
	goji.Get("/:name/:repo_tag", buildsShowHandler)
	goji.Post("/_github", postReceiveHook)
	goji.Serve()
}
开发者ID:wakermahmud,项目名称:jekyll-build-server,代码行数:25,代码来源:jekyll-build-server.go

示例2: main

func main() {
	defer glog.Flush()
	glog.Info("Initializing shellscript executor server")

	port := flag.String("P", "6304", "port")
	flag.Parse()

	flag.Lookup("logtostderr").Value.Set("true")

	EnvSettingsInit()
	//read dictionary into memory
	dicData, err := ioutil.ReadFile(ProjectEnvSettings.DictionaryPath)
	if err != nil {
		FailOnError(err, fmt.Sprintf("Error[%s] reading dictionary from path[%]", err, ProjectEnvSettings.DictionaryPath))
	}

	glog.Infof("Dictionary[%s]", dicData)

	if err := json.Unmarshal(dicData, &dictionary); err != nil {
		FailOnError(err, fmt.Sprintf("Error[%s] decode json dictionary from path[%] with content[%s]", err, ProjectEnvSettings.DictionaryPath, dicData))
	}

	goji.Get("/shell/execute/:action_name", executeShellScriptHandler)

	flag.Set("bind", ":"+*port)
	goji.Serve()
}
开发者ID:jmptrader,项目名称:shellscript-executor,代码行数:27,代码来源:server.go

示例3: main

func main() {
	filename := flag.String("config", "config.toml", "Path to configuration file")
	flag.Parse()
	fmt.Println(*filename)
	goji.Get("/hello/:name", hello)
	goji.Serve()
}
开发者ID:kiskovacs,项目名称:hugo-cms,代码行数:7,代码来源:main.go

示例4: main

func main() {
	var cfg Config
	stderrBackend := logging.NewLogBackend(os.Stderr, "", 0)
	stderrFormatter := logging.NewBackendFormatter(stderrBackend, stdout_log_format)
	logging.SetBackend(stderrFormatter)
	logging.SetFormatter(stdout_log_format)

	if cfg.ListenAddr == "" {
		cfg.ListenAddr = "127.0.0.1:63636"
	}
	flag.Set("bind", cfg.ListenAddr)
	log.Info("Starting app")
	log.Debug("version: %s", version)

	webApp := webapi.New()
	goji.Get("/dns", webApp.Dns)
	goji.Post("/dns", webApp.Dns)
	goji.Get("/isItWorking", webApp.Healthcheck)

	goji.Post("/redir/batch", webApp.BatchAddRedir)
	goji.Post("/redir/:from/:to", webApp.AddRedir)
	goji.Delete("/redir/:from", webApp.DeleteRedir)
	goji.Get("/redir/list", webApp.ListRedir)

	//_, _ = api.New(api.CallbackList{})

	goji.Serve()
}
开发者ID:efigence,项目名称:go-powerdns,代码行数:28,代码来源:powerdns-remote.go

示例5: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	log.SetOutput(ioutil.Discard) // add line 3
	db, err := sql.Open("mysql", connectionString)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	db.SetMaxIdleConns(maxConnectionCount)
	worldStatement, err = db.Prepare(worldSelect)
	if err != nil {
		log.Fatal(err)
	}
	fortuneStatement, err = db.Prepare(fortuneSelect)
	if err != nil {
		log.Fatal(err)
	}
	updateStatement, err = db.Prepare(worldUpdate)
	if err != nil {
		log.Fatal(err)
	}

	flag.Set("bind", ":8080")
	goji.Get("/json", serializeJson)
	goji.Get("/db", singleQuery)
	goji.Get("/queries", multipleQueries)
	goji.Get("/fortunes", fortunes)
	goji.Get("/plaintext", plaintext)
	goji.Get("/updates", dbupdate)
	goji.Serve()
}
开发者ID:cmsimike,项目名称:FrameworkBenchmarks,代码行数:30,代码来源:server.go

示例6: main

func main() {
	render := render.New(render.Options{
		Directory:  "src/views",
		Extensions: []string{".html"},
	})

	http.HandleFunc("/img/", serveResource)
	http.HandleFunc("/css/", serveResource)
	http.HandleFunc("/js/", serveResource)

	goji.Get("/hello/:name", func(c web.C, w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"])
	})

	goji.Get("/wow", func(c web.C, w http.ResponseWriter, r *http.Request) {
		render.HTML(w, http.StatusOK, "index", nil)
	})

	goji.Get("/bar", func(c web.C, w http.ResponseWriter, r *http.Request) {
		render.HTML(w, http.StatusOK, "bar", nil)
	})

	goji.Get("/", func(c web.C, w http.ResponseWriter, r *http.Request) {
		render.HTML(w, http.StatusOK, "index", nil)
	})

	goji.Serve()
}
开发者ID:AppyCat,项目名称:goji-app,代码行数:28,代码来源:main.go

示例7: WebServer

func WebServer(ip string, port int) {

	goji.Get("/", func(c web.C, w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page!")
	})

	goji.Get("/search", func(c web.C, w http.ResponseWriter, r *http.Request) {
		filter := db.Filter{}
		options := &db.Options{}

		r.ParseForm()
		startDate := r.Form.Get("startDate")
		endDate := r.Form.Get("endDate")

		if startDate != "" {
			filter.StartDate = startDate
		}

		if endDate != "" {
			filter.EndDate = endDate
		}

		order := r.Form["orderby"]
		options.Sort = order

		var results []db.DbObject

		db.Db.Find(&filter, options, &results)
		jsonResults, err := json.Marshal(results)
		if err != nil {
			fmt.Fprint(w, err)
			return
		}

		fmt.Fprintf(w, "%s", string(jsonResults))
	})

	goji.Get("/call/:id", func(c web.C, w http.ResponseWriter, r *http.Request) {
		callId := c.URLParams["id"]
		fmt.Print(callId)
		filter := db.NewFilter()
		options := &db.Options{}

		filter.Equals["callid"] = callId

		var results []db.DbObject
		db.Db.Find(&filter, options, &results)

		jsonResults, err := json.Marshal(results)
		if err != nil {
			fmt.Fprint(w, err)
			return
		}

		fmt.Fprintf(w, "%s", string(jsonResults))

	})

	goji.Serve()
}
开发者ID:gdoermann,项目名称:flanders,代码行数:60,代码来源:main.go

示例8: main

func main() {
	goji.Get("/", IndexHandler) // Doesn't need CSRF protection (no POST/PUT/DELETE actions).

	signup := web.New()
	goji.Handle("/signup/*", signup)
	// But our signup forms do, so we add nosurf to their middleware stack (only).
	signup.Use(nosurf.NewPure)
	signup.Get("/signup/new", ShowSignupForm)
	signup.Post("/signup/submit", SubmitSignupForm)

	admin := web.New()
	// A more advanced example: we enforce secure cookies (HTTPS only),
	// set a domain and keep the expiry time low.
	a := nosurf.New(admin)
	a.SetBaseCookie(http.Cookie{
		Name:     "csrf_token",
		Domain:   "localhost",
		Path:     "/admin",
		MaxAge:   3600 * 4,
		HttpOnly: true,
		Secure:   true,
	})

	// Our /admin/* routes now have CSRF protection.
	goji.Handle("/admin/*", a)

	goji.Serve()
}
开发者ID:marswang,项目名称:nosurf,代码行数:28,代码来源:goji.go

示例9: main

func main() {
	goji.Use(ContentTypeJson)
	goji.Get("/jokes/:jokeId", showJoke)
	goji.Serve()

	db.Close()
}
开发者ID:ksimka,项目名称:goapi-demo,代码行数:7,代码来源:server.go

示例10: main

func main() {
	// Initalize database.
	ExecuteSchemas()
	// Serve static files.
	staticDirs := []string{"bower_components", "res"}
	for _, d := range staticDirs {
		static := web.New()
		pattern, prefix := fmt.Sprintf("/%s/*", d), fmt.Sprintf("/%s/", d)
		static.Get(pattern, http.StripPrefix(prefix, http.FileServer(http.Dir(d))))
		http.Handle(prefix, static)
	}

	goji.Use(applySessions)
	goji.Use(context.ClearHandler)

	goji.Get("/", handler(serveIndex))
	goji.Get("/login", handler(serveLogin))
	goji.Get("/github_callback", handler(serveGitHubCallback))
	// TODO(samertm): Make this POST /user/email.
	goji.Post("/save_email", handler(serveSaveEmail))

	goji.Post("/group/create", handler(serveGroupCreate))
	goji.Post("/group/:group_id/refresh", handler(serveGroupRefresh))
	goji.Get("/group/:group_id/join", handler(serveGroupJoin))
	goji.Get("/group/:group_id", handler(serveGroup))
	goji.Get("/group/:group_id/user/:user_id/stats.svg", handler(serveUserStatsSVG))

	goji.Serve()
}
开发者ID:samertm,项目名称:githubstreaks,代码行数:29,代码来源:main.go

示例11: Start

func (s *GossamerServer) Start() {
	goji.Get("/", s.HandleWebUiIndex)
	goji.Get("/things.html", s.HandleWebUiThings)
	goji.Get("/sensors.html", s.HandleWebUiSensors)
	goji.Get("/observations.html", s.HandleWebUiObservations)
	goji.Get("/observedproperties.html", s.HandleWebUiObservedProperties)
	goji.Get("/locations.html", s.HandleWebUiLocations)
	goji.Get("/datastreams.html", s.HandleWebUiDatastreams)
	goji.Get("/featuresofinterest.html", s.HandleWebUiFeaturesOfInterest)
	goji.Get("/historiclocations.html", s.HandleWebUiHistoricLocations)
	goji.Get("/css/*", s.HandleWebUiResources)
	goji.Get("/img/*", s.HandleWebUiResources)
	goji.Get("/js/*", s.HandleWebUiResources)

	goji.Get("/v1.0", s.handleRootResource)
	goji.Get("/v1.0/", s.handleRootResource)

	goji.Get("/v1.0/*", s.HandleGet)
	goji.Post("/v1.0/*", s.HandlePost)
	goji.Put("/v1.0/*", s.HandlePut)
	goji.Delete("/v1.0/*", s.HandleDelete)
	goji.Patch("/v1.0/*", s.HandlePatch)

	flag.Set("bind", ":"+strconv.Itoa(s.port))

	log.Println("Start Server on port ", s.port)
	goji.Serve()
}
开发者ID:zubairhamed,项目名称:gossamer,代码行数:28,代码来源:server.go

示例12: main

func main() {
	var dumpConf bool
	var confFile string

	flag.BoolVar(&dumpConf, "dumpconf", false, "dump the default configuration file")
	flag.StringVar(&confFile, "conf", "", "use this alternative configuration file")
	flag.Parse()

	stdoutLogger = log.New(os.Stderr, "", log.Flags())

	if dumpConf {
		dumpDefaultConf()
		return
	}

	rand.Seed(time.Now().Unix())

	if confFile != "" {
		setConf(confFile)
	}

	if conf.RealIP {
		goji.Insert(middleware.RealIP, middleware.Logger)
	}

	goji.Get("/", root)
	goji.Get("/:id", getPaste)
	goji.Post("/", createPaste)
	goji.Serve()
}
开发者ID:Cubox-,项目名称:pasteyourmom,代码行数:30,代码来源:pasteyourmom.go

示例13: main

func main() {
	rand.Seed(time.Now().UnixNano())
	goji.Get("/slow", slow)
	goji.Get("/bad", bad)
	goji.Get("/timeout", timeout)
	goji.Serve()
}
开发者ID:segfault88,项目名称:rubyvgo1,代码行数:7,代码来源:main.go

示例14: main

func main() {
	goji.Get("/hello/:name", hello)

	staticPattern := regexp.MustCompile("^/(css|js)")
	goji.Handle(staticPattern, http.FileServer(http.Dir("./static")))
	goji.Serve()
}
开发者ID:MacoTasu,项目名称:goji-and-go-xslate-sample,代码行数:7,代码来源:server.go

示例15: initServer

// initServer initialize and start the web server.
func initServer(db *client.DbClient) {
	// Initialize the API controller
	controllers.Init(db)

	// Staticbin middleware
	goji.Use(gojistaticbin.Staticbin("static", Asset, gojistaticbin.Options{
		SkipLogging: true,
		IndexFile:   "index.html",
	}))

	// Httpauth middleware
	if options.AuthUser != "" && options.AuthPass != "" {
		goji.Use(httpauth.SimpleBasicAuth(options.AuthUser, options.AuthPass))
	}

	goji.Get("/api/info", controllers.Info)
	goji.Get("/api/table", controllers.Tables)
	goji.Get("/api/table/:name", controllers.Table)
	goji.Get("/api/table/:name/info", controllers.TableInfo)
	goji.Get("/api/table/:name/sql", controllers.TableSql)
	goji.Get("/api/table/:name/indexes", controllers.TableIndexes)
	goji.Get("/api/query", controllers.Query)
	goji.Post("/api/query", controllers.Query)

	address := fmt.Sprintf("%s:%d", options.HttpHost, options.HttpPort)
	flag.Set("bind", address)

	go goji.Serve()
}
开发者ID:changwng,项目名称:sqliteweb,代码行数:30,代码来源:main.go


注:本文中的github.com/zenazn/goji.Serve函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。