move into module

This commit is contained in:
Jeffrey Paul 2019-10-29 10:05:18 -07:00
parent 73f2860add
commit 91e01403f8
9 changed files with 66 additions and 48 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
merp
merpd
prod-secrets.yaml

View File

@ -10,12 +10,12 @@ RUN tar cvfz go-src.tgz src && du -sh *
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
COPY --from=builder /go/go-src.tgz /usr/local/src/go-src.tgz
#COPY --from=builder /go/src /usr/local/src/go
CMD /bin/merp
CMD /bin/merpd
# FIXME add testing

View File

@ -29,15 +29,15 @@ endif
default: run
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) .
clean:
rm $(APPNAME)
rm $(APPNAME)d
fmt:
go fmt *.go

44
main.go
View File

@ -1,11 +1,7 @@
//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"
import "github.com/sneak/merp/merp"
var Version string
var Buildtime string
@ -14,37 +10,9 @@ var Buildarch string
var Appname string
func main() {
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)
}
merp.Version = Version
merp.Buildtime = Buildtime
merp.Builduser = Builduser
merp.Buildarch = Buildarch
merp.Start()
}

50
merp/main.go Normal file
View 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)
}
}

View File

@ -1,4 +1,4 @@
package main
package merp
import "encoding/json"
import "net/http"
@ -8,7 +8,7 @@ import "time"
import "github.com/gin-gonic/gin"
import "github.com/google/uuid"
import "github.com/rs/zerolog/log"
import "github.com/sneak/merp/models"
import "github.com/sneak/merp/merp/models"
func thingRegex() *regexp.Regexp {
THING_REGEX, e := regexp.Compile(`^[a-zA-Z0-9\_\-]+$`)

View File

@ -1,5 +1,5 @@
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
package main
package merp
import "fmt"
import "net/http"