commit 9d9e3445467e2f8803f28e9ea1fc6262479a5419 Author: Jeffrey Paul Date: Thu Oct 24 03:38:16 2019 -0700 boilerplate only diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..916b263 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..124022b --- /dev/null +++ b/Makefile @@ -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 . diff --git a/fediverse-archive b/fediverse-archive new file mode 100755 index 0000000..86fdf09 Binary files /dev/null and b/fediverse-archive differ diff --git a/fetcher.go b/fetcher.go new file mode 100644 index 0000000..aa3718f --- /dev/null +++ b/fetcher.go @@ -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") + +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..b6c2162 --- /dev/null +++ b/main.go @@ -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 +}