move into module
This commit is contained in:
parent
73f2860add
commit
91e01403f8
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
|||||||
merp
|
merpd
|
||||||
prod-secrets.yaml
|
prod-secrets.yaml
|
||||||
|
@ -10,12 +10,12 @@ RUN tar cvfz go-src.tgz src && du -sh *
|
|||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
COPY --from=builder /go/src/github.com/sneak/merp/merp /bin/merp
|
COPY --from=builder /go/src/github.com/sneak/merp/merpd /bin/merpd
|
||||||
|
|
||||||
# put the source in there too for safekeeping
|
# put the source in there too for safekeeping
|
||||||
COPY --from=builder /go/go-src.tgz /usr/local/src/go-src.tgz
|
COPY --from=builder /go/go-src.tgz /usr/local/src/go-src.tgz
|
||||||
#COPY --from=builder /go/src /usr/local/src/go
|
#COPY --from=builder /go/src /usr/local/src/go
|
||||||
|
|
||||||
CMD /bin/merp
|
CMD /bin/merpd
|
||||||
|
|
||||||
# FIXME add testing
|
# FIXME add testing
|
||||||
|
8
Makefile
8
Makefile
@ -29,15 +29,15 @@ endif
|
|||||||
default: run
|
default: run
|
||||||
|
|
||||||
run: build
|
run: build
|
||||||
DEBUG=1 PORT=1111 ./$(APPNAME)
|
DEBUG=1 PORT=1111 ./$(APPNAME)d
|
||||||
|
|
||||||
build: ./$(APPNAME)
|
build: ./$(APPNAME)d
|
||||||
|
|
||||||
./$(APPNAME): *.go models/*.go
|
./$(APPNAME)d: *.go merp/*.go merp/models/*.go
|
||||||
go build -o $@ $(GOFLAGS) .
|
go build -o $@ $(GOFLAGS) .
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(APPNAME)
|
rm $(APPNAME)d
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt *.go
|
go fmt *.go
|
||||||
|
44
main.go
44
main.go
@ -1,11 +1,7 @@
|
|||||||
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "os"
|
import "github.com/sneak/merp/merp"
|
||||||
import "time"
|
|
||||||
import "github.com/rs/zerolog"
|
|
||||||
import "github.com/rs/zerolog/log"
|
|
||||||
import "golang.org/x/crypto/ssh/terminal"
|
|
||||||
|
|
||||||
var Version string
|
var Version string
|
||||||
var Buildtime string
|
var Buildtime string
|
||||||
@ -14,37 +10,9 @@ var Buildarch string
|
|||||||
var Appname string
|
var Appname string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
initLogging()
|
merp.Version = Version
|
||||||
identify()
|
merp.Buildtime = Buildtime
|
||||||
serve()
|
merp.Builduser = Builduser
|
||||||
}
|
merp.Buildarch = Buildarch
|
||||||
|
merp.Start()
|
||||||
func identify() {
|
|
||||||
log.Info().
|
|
||||||
Str("app", Appname).
|
|
||||||
Str("version", Version).
|
|
||||||
Str("buildarch", Buildarch).
|
|
||||||
Str("buildtime", Buildtime).
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
50
merp/main.go
Normal file
50
merp/main.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||||
|
package merp
|
||||||
|
|
||||||
|
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
|
||||||
|
var Builduser string
|
||||||
|
var Buildarch string
|
||||||
|
var Appname string
|
||||||
|
|
||||||
|
func Start() {
|
||||||
|
initLogging()
|
||||||
|
identify()
|
||||||
|
serve()
|
||||||
|
}
|
||||||
|
|
||||||
|
func identify() {
|
||||||
|
log.Info().
|
||||||
|
Str("app", Appname).
|
||||||
|
Str("version", Version).
|
||||||
|
Str("buildarch", Buildarch).
|
||||||
|
Str("buildtime", Buildtime).
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package merp
|
||||||
|
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
import "net/http"
|
import "net/http"
|
||||||
@ -8,7 +8,7 @@ import "time"
|
|||||||
import "github.com/gin-gonic/gin"
|
import "github.com/gin-gonic/gin"
|
||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
import "github.com/rs/zerolog/log"
|
import "github.com/rs/zerolog/log"
|
||||||
import "github.com/sneak/merp/models"
|
import "github.com/sneak/merp/merp/models"
|
||||||
|
|
||||||
func thingRegex() *regexp.Regexp {
|
func thingRegex() *regexp.Regexp {
|
||||||
THING_REGEX, e := regexp.Compile(`^[a-zA-Z0-9\_\-]+$`)
|
THING_REGEX, e := regexp.Compile(`^[a-zA-Z0-9\_\-]+$`)
|
@ -1,5 +1,5 @@
|
|||||||
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
||||||
package main
|
package merp
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "net/http"
|
import "net/http"
|
Loading…
Reference in New Issue
Block a user