Example #1
0
func main() {
	rand.Seed(time.Now().UnixNano())
	web.Config.CookieSecret = "7C19QRmwf3mHZ9CPAaPQ0hsWeufKd"
	web.Get("/", func(ctx *web.Context) string {
		ctx.Redirect(302, "/said")
		return ""
	})
	web.Get("/said", func() string { return form })
	web.Post("/say", func(ctx *web.Context) string {
		uid := fmt.Sprintf("%d\n", rand.Int63())
		ctx.SetSecureCookie("user", uid, 3600)
		users[uid] = ctx.Params["said"]
		return `<a href="/final">Click Here</a>`
	})
	web.Get("/final", func(ctx *web.Context) string {
		uid, _ := ctx.GetSecureCookie("user")
		return "You said " + users[uid]
	})
	web.Run("0.0.0.0:9999")
}
Example #2
0
File: logger.go Project: widaT/web
func main() {
	f, err := os.Create("server.log")
	if err != nil {
		println(err.Error())
		return
	}
	logger := log.New(f, "", log.Ldate|log.Ltime)
	web.Get("/(.*)", hello)
	web.SetLogger(logger)
	web.Run("0.0.0.0:9999")
}
Example #3
0
File: tls.go Project: widaT/web
func main() {
	config := tls.Config{
		Time: nil,
	}

	config.Certificates = make([]tls.Certificate, 1)
	var err error
	config.Certificates[0], err = tls.X509KeyPair([]byte(cert), []byte(pkey))
	if err != nil {
		println(err.Error())
		return
	}

	// you must access the server with an HTTP address, i.e https://localhost:9999/world
	web.Get("/(.*)", hello)
	web.RunTLS("0.0.0.0:9999", &config)
}
Example #4
0
File: cookie.go Project: widaT/web
func main() {
	web.Get("/", index)
	web.Post("/update", update)
	web.Run("0.0.0.0:9999")
}
Example #5
0
File: params.go Project: widaT/web
func main() {
	web.Get("/", index)
	web.Post("/process", process)
	web.Run("0.0.0.0:9999")
}
Example #6
0
func main() {
	web.Get("/([0-9]+)", hello)
	web.Run("0.0.0.0:9999")
}
Example #7
0
func main() {
	web.Get("/", index)
	web.Post("/multipart", multipart)
	web.Run("0.0.0.0:9999")
}