latest
This commit is contained in:
parent
2947ec68c1
commit
ca5a726e75
3
app.yaml
3
app.yaml
|
@ -1,8 +1,5 @@
|
|||
runtime: custom
|
||||
env: flex
|
||||
|
||||
env_variables:
|
||||
DEBUG: 1
|
||||
|
||||
includes:
|
||||
- prod-secrets.yaml
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
const basePage = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{.Title}}</title>
|
||||
{{.Head}}
|
||||
</head>
|
||||
<body>
|
||||
{{.Body}}
|
||||
</body>
|
||||
</html>`
|
|
@ -0,0 +1,28 @@
|
|||
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||
package main
|
||||
|
||||
import "os"
|
||||
import "time"
|
||||
import "github.com/rs/zerolog"
|
||||
import "github.com/rs/zerolog/log"
|
||||
import "golang.org/x/crypto/ssh/terminal"
|
||||
|
||||
func initLogging() {
|
||||
|
||||
// always log in UTC
|
||||
zerolog.TimestampFunc = func() time.Time {
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
log.Logger = log.With().Caller().Stack().Logger()
|
||||
|
||||
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339Nano}
|
||||
log.Logger = zerolog.New(output).With().Caller().Stack().Logger().With().Timestamp().Logger()
|
||||
}
|
||||
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
}
|
26
main.go
26
main.go
|
@ -1,11 +1,7 @@
|
|||
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||
package merp
|
||||
package main
|
||||
|
||||
import "os"
|
||||
import "time"
|
||||
import "github.com/rs/zerolog"
|
||||
import "github.com/rs/zerolog/log"
|
||||
import "golang.org/x/crypto/ssh/terminal"
|
||||
|
||||
var Version string
|
||||
var Buildtime string
|
||||
|
@ -28,23 +24,3 @@ func identify() {
|
|||
Str("builduser", Builduser).
|
||||
Msg("starting")
|
||||
}
|
||||
|
||||
func initLogging() {
|
||||
|
||||
// always log in UTC
|
||||
zerolog.TimestampFunc = func() time.Time {
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
log.Logger = log.With().Caller().Stack().Logger()
|
||||
|
||||
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339Nano}
|
||||
log.Logger = zerolog.New(output).With().Caller().Stack().Logger().With().Timestamp().Logger()
|
||||
}
|
||||
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
}
|
||||
|
|
10
merp.go
10
merp.go
|
@ -1,4 +1,4 @@
|
|||
package merp
|
||||
package main
|
||||
|
||||
import "encoding/json"
|
||||
import "net/http"
|
||||
|
@ -169,10 +169,10 @@ func HandleNewMerp() gin.HandlerFunc {
|
|||
"by": "merping",
|
||||
"the": "merp",
|
||||
"with": gin.H{
|
||||
"thing": thing,
|
||||
"created": atString,
|
||||
"content": respContent,
|
||||
"id": u.String(),
|
||||
"thing": thing,
|
||||
"created": atString,
|
||||
"content": respContent,
|
||||
"transaction": u.String(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
18
server.go
18
server.go
|
@ -1,5 +1,5 @@
|
|||
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||
package merp
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import "net/http"
|
||||
|
@ -11,6 +11,12 @@ import "github.com/gin-gonic/gin"
|
|||
import "github.com/dn365/gin-zerolog"
|
||||
|
||||
func serve() {
|
||||
s := getServer()
|
||||
s.ListenAndServe()
|
||||
}
|
||||
|
||||
func getRouter() *gin.Engine {
|
||||
|
||||
if os.Getenv("DEBUG") == "" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
@ -32,10 +38,18 @@ func serve() {
|
|||
})
|
||||
|
||||
// call it, it returns the appropriate handler function
|
||||
// so we can execute some code at startup time
|
||||
// and not just request time
|
||||
r.GET("/merp/for/:thing", HandleNewMerp())
|
||||
r.GET("/get/latest/merp/for/:thing", GetLatestMerp())
|
||||
r.GET("/get/merps/for/:thing", GetLatestMerps())
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func getServer() *http.Server {
|
||||
r := getRouter()
|
||||
|
||||
port := "8080"
|
||||
if os.Getenv("PORT") != "" {
|
||||
port = os.Getenv("PORT")
|
||||
|
@ -48,5 +62,5 @@ func serve() {
|
|||
WriteTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
}
|
||||
s.ListenAndServe()
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue