merp/server.go

36 lines
755 B
Go
Raw Normal View History

2019-10-03 19:30:04 +00:00
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
package main
2019-10-25 15:09:31 +00:00
import "fmt"
import "os"
import "github.com/rs/zerolog/log"
2019-10-25 12:01:38 +00:00
import "github.com/hoisie/web"
2019-10-03 19:30:04 +00:00
2019-10-25 15:09:31 +00:00
/* func initDb() {
db, err := sql.Open("postgres", os.Getenv("POSTGRES_DB_URL"))
if err != nil {
log.Fatal().Msg(err)
2019-10-25 12:01:38 +00:00
}
}
2019-10-25 15:09:31 +00:00
*/
2019-10-25 12:01:38 +00:00
2019-10-25 15:09:31 +00:00
const defaultPort int = 8080
2019-10-03 19:30:04 +00:00
2019-10-25 15:09:31 +00:00
func serve() {
port := os.Getenv("PORT")
if port == "" {
port = fmt.Sprintf("%d", defaultPort)
}
// FIXME web.SetLogger(log.Logger)
web.Get(`/dweet/for/([A-Za-z0-9\-\_\.]+)`, dweetHandler)
web.Run(fmt.Sprintf("0.0.0.0:%s", port))
2019-10-03 19:30:04 +00:00
}
2019-10-25 15:09:31 +00:00
func dweetHandler(ctx *web.Context, val string) string {
log.Info().Msg("in hello()")
for k, v := range ctx.Params {
println(k, v)
2019-10-03 19:30:04 +00:00
}
2019-10-25 15:09:31 +00:00
return ("hello " + val)
2019-10-03 19:30:04 +00:00
}