本文整理汇总了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()
}
示例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()
}
示例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()
}
示例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()
}
示例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()
}
示例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()
}
示例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()
}
示例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()
}
示例9: main
func main() {
goji.Use(ContentTypeJson)
goji.Get("/jokes/:jokeId", showJoke)
goji.Serve()
db.Close()
}
示例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()
}
示例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()
}
示例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()
}
示例13: main
func main() {
rand.Seed(time.Now().UnixNano())
goji.Get("/slow", slow)
goji.Get("/bad", bad)
goji.Get("/timeout", timeout)
goji.Serve()
}
示例14: main
func main() {
goji.Get("/hello/:name", hello)
staticPattern := regexp.MustCompile("^/(css|js)")
goji.Handle(staticPattern, http.FileServer(http.Dir("./static")))
goji.Serve()
}
示例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()
}