boilerplate only

This commit is contained in:
Jeffrey Paul 2019-10-24 03:38:16 -07:00
commit 9d9e344546
5 changed files with 120 additions and 0 deletions

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM golang:1.13 as builder
WORKDIR /go/src/github.com/sneak/fediverse-archive
COPY . .
RUN go get -v && make build
# this container doesn't do anything except hold the build artifact
# and make sure it compiles.
FROM alpine
COPY --from=builder /go/src/github.com/sneak/fediverse-archive/fediverse-archive /bin/fediverse-archive
CMD /bin/fediverse-archive
# FIXME add testing

30
Makefile Normal file
View File

@ -0,0 +1,30 @@
VERSION := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BUILDUSER := $(shell whoami)
BUILDHOST := $(shell hostname -s)
BUILDARCH := $(shell uname -m)
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
GOLDFLAGS += -X main.Builduser=$(BUILDUSER)@$(BUILDHOST)
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
GOFLAGS = -ldflags "$(GOLDFLAGS)"
default: rundebug
rundebug: build
./fediverse-archive -debug
run: build
./fediverse-archvie
build: ./fediverse-archive
./fediverse-archive: *.go
go build -o $@ $(GOFLAGS) .
fmt:
go fmt *.go
test:
docker build -t sneak/fediverse-archive .

BIN
fediverse-archive Executable file

Binary file not shown.

23
fetcher.go Normal file
View File

@ -0,0 +1,23 @@
package main
import (
"github.com/rs/zerolog/log"
)
// https://mastodon.social/api/v1/timelines/public?limit=40&local=true
func findPleromaInstances() {
//var url = "https://distsn.org/cgi-bin/distsn-pleroma-instances-api.cgi?shuffle"
}
func fetchPleromaToots(url string) {
//https://%s/api/statuses/public_and_external_timeline.json?count=100
}
func fetchLatestToots(lastId int) {
log.Debug().Msg("This message appears only when log level set to Debug")
log.Info().Msg("This message appears when log level set to Debug or Info")
}

50
main.go Normal file
View File

@ -0,0 +1,50 @@
package main
import (
"flag"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golang.org/x/crypto/ssh/terminal"
"os"
)
var Version string
var Buildtime string
var Builduser string
var Buildarch string
func main() {
os.Exit(app())
}
func identify() {
log.Debug().
Str("version", Version).
Str("buildarch", Buildarch).
Str("buildtime", Buildtime).
Str("builduser", Builduser).Send()
}
func app() int {
if terminal.IsTerminal(int(os.Stdout.Fd())) {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
debug := flag.Bool("debug", false, "sets log level to debug")
flag.Parse()
identify()
log.Print("hello world")
// Default level for this example is info, unless debug flag is present
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if *debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
log.Debug().Msg("This message appears only when log level set to Debug")
log.Info().Msg("This message appears when log level set to Debug or Info")
return 0
}