From 07f4fdad65c293185fd2cbaa7096153e3c68b9d9 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Sun, 16 Oct 2022 21:28:55 +0000 Subject: [PATCH] chore: fix website Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> --- Dockerfile | 8 ++++---- go.sum | 7 +++++++ pkg/calcapi/api_calc.go | 20 ++++++++++++++++++++ pkg/calcapi/svc.go | 4 +++- pkg/dashboard/dashboard.go | 4 ++++ tools.go | 8 ++++++++ 6 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 tools.go diff --git a/Dockerfile b/Dockerfile index a7b82e60..64bb34ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ -FROM golang:1.13-alpine as builder +FROM golang:1.19-alpine as builder WORKDIR /go/src/ultre.me/calcbiz -RUN apk --no-cache --update add nodejs-npm make gcc g++ musl-dev openssl-dev git -RUN go get -u github.com/gobuffalo/packr/packr +RUN apk --no-cache --update add npm make gcc g++ musl-dev openssl-dev git ENV GO111MODULE=on COPY go.* /go/src/ultre.me/calcbiz/ RUN go mod download +RUN go install github.com/gobuffalo/packr/packr COPY . /go/src/ultre.me/calcbiz/ RUN make packr RUN make install -FROM alpine:3.10 +FROM alpine:3.13 RUN apk --no-cache --update add ca-certificates && update-ca-certificates COPY --from=builder /go/bin/calcbiz /bin/calcbiz #COPY ./static . diff --git a/go.sum b/go.sum index 50a1e9a2..a77bda0a 100644 --- a/go.sum +++ b/go.sum @@ -68,11 +68,13 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= github.com/gobuffalo/envy v1.8.1 h1:RUr68liRvs0TS1D5qdW3mQv2SjAsu1QWMCx1tG4kDjs= github.com/gobuffalo/envy v1.8.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w= +github.com/gobuffalo/logger v1.0.0 h1:xw9Ko9EcC5iAFprrjJ6oZco9UpzS5MQ4jAwghsLHdy4= github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4= github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg= github.com/gobuffalo/packr v1.30.1/go.mod h1:ljMyFO2EcrnzsHsN99cvbq055Y9OhRrIaviy289eRuk= +github.com/gobuffalo/packr/v2 v2.5.1 h1:TFOeY2VoGamPjQLiNDT3mn//ytzk236VMO2j7iHxJR4= github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw= github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0= github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic= @@ -135,6 +137,7 @@ github.com/huandu/xstrings v1.2.1 h1:v6IdmkCnDhJG/S0ivr58PeIfg+tyhqQYy4YsCsQ0Pdc github.com/huandu/xstrings v1.2.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jinzhu/gorm v1.9.11 h1:gaHGvE+UnWGlbWG4Y3FUwY1EcZ5n6S9WtqBA/uySMLE= @@ -149,6 +152,7 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/karrick/godirwalk v1.10.12 h1:BqUm+LuJcXjGv1d2mj3gBiQyrQ57a0rYoAmhvJQ7RDU= github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -262,8 +266,10 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -359,6 +365,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/pkg/calcapi/api_calc.go b/pkg/calcapi/api_calc.go index 7b917796..8db7c33c 100644 --- a/pkg/calcapi/api_calc.go +++ b/pkg/calcapi/api_calc.go @@ -158,6 +158,10 @@ func (svc *svc) AlternateLogo(_ context.Context, input *AlternateLogo_Input) (*A } func (svc *svc) SoundcloudMe(_ context.Context, input *SoundcloudMe_Input) (*SoundcloudMe_Output, error) { + if svc.soundcloud == nil { + return nil, fmt.Errorf("soundcloud API is disconnected") + } + me, err := svc.soundcloud.Me() if err != nil { return nil, err @@ -166,6 +170,10 @@ func (svc *svc) SoundcloudMe(_ context.Context, input *SoundcloudMe_Input) (*Sou } func (svc *svc) SoundcloudPlaylists(_ context.Context, input *SoundcloudPlaylists_Input) (*SoundcloudPlaylists_Output, error) { + if svc.soundcloud == nil { + return nil, fmt.Errorf("soundcloud API is disconnected") + } + playlists, err := svc.soundcloud.GetPlaylists() if err != nil { return nil, err @@ -174,6 +182,10 @@ func (svc *svc) SoundcloudPlaylists(_ context.Context, input *SoundcloudPlaylist } func (svc *svc) SoundcloudPlaylist(_ context.Context, input *SoundcloudPlaylist_Input) (*SoundcloudPlaylist_Output, error) { + if svc.soundcloud == nil { + return nil, fmt.Errorf("soundcloud API is disconnected") + } + if input.PlaylistId < 1 { // pick random playlist, err := svc.soundcloud.GetRandomPlaylist() if err != nil { @@ -189,6 +201,10 @@ func (svc *svc) SoundcloudPlaylist(_ context.Context, input *SoundcloudPlaylist_ } func (svc *svc) SoundcloudTracks(_ context.Context, input *SoundcloudTracks_Input) (*SoundcloudTracks_Output, error) { + if svc.soundcloud == nil { + return nil, fmt.Errorf("soundcloud API is disconnected") + } + tracks, err := svc.soundcloud.GetTracks() if err != nil { return nil, err @@ -197,6 +213,10 @@ func (svc *svc) SoundcloudTracks(_ context.Context, input *SoundcloudTracks_Inpu } func (svc *svc) SoundcloudTrack(_ context.Context, input *SoundcloudTrack_Input) (*SoundcloudTrack_Output, error) { + if svc.soundcloud == nil { + return nil, fmt.Errorf("soundcloud API is disconnected") + } + if input.TrackId < 1 { // pick random track, err := svc.soundcloud.GetRandomTrack() if err != nil { diff --git a/pkg/calcapi/svc.go b/pkg/calcapi/svc.go index d907f156..28edddb0 100644 --- a/pkg/calcapi/svc.go +++ b/pkg/calcapi/svc.go @@ -50,7 +50,9 @@ func New(db *gorm.DB, opts Options) (Service, error) { } svc := &svc{opts: opts, startTime: time.Now(), db: db} - svc.soundcloud = soundcloud.New(opts.SoundcloudClientID, uint64(opts.SoundcloudUserID)) + if opts.SoundcloudClientID != "" { + svc.soundcloud = soundcloud.New(opts.SoundcloudClientID, uint64(opts.SoundcloudUserID)) + } svc.dashboard = dashboard.New(&dashboard.Options{Soundcloud: svc.soundcloud}) // svc.dashboard.SetSoundCloud(&soundcloud) return svc, nil diff --git a/pkg/dashboard/dashboard.go b/pkg/dashboard/dashboard.go index 8435b146..80cd200c 100644 --- a/pkg/dashboard/dashboard.go +++ b/pkg/dashboard/dashboard.go @@ -129,6 +129,10 @@ func (d *Dashboard) hackEntries(limit int) (*Entries, error) { func (d *Dashboard) trackEntries(limit int) (*Entries, error) { entries := newEntries() + if d.opts.Soundcloud == nil { + return entries, nil + } + tracks, err := d.opts.Soundcloud.GetTracks() if err != nil { return entries, err diff --git a/tools.go b/tools.go new file mode 100644 index 00000000..3424a3d5 --- /dev/null +++ b/tools.go @@ -0,0 +1,8 @@ +//go:build tools +// +build tools + +package calcbiz + +import ( + _ "github.com/gobuffalo/packr/packr" // packr +)