mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Clean backend code
This commit is contained in:
12
Dockerfile
12
Dockerfile
@@ -1,12 +1,6 @@
|
||||
FROM node:8-slim AS frontend_builder
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN npm install
|
||||
RUN npm run build
|
||||
|
||||
FROM golang:1.11.2 AS backend_builder
|
||||
WORKDIR /podsync
|
||||
COPY --from=frontend_builder /app .
|
||||
COPY . .
|
||||
ENV GOOS=linux
|
||||
ENV GOARCH=amd64
|
||||
ENV CGO_ENABLED=0
|
||||
@@ -15,9 +9,5 @@ RUN go build -o server -v ./cmd/app
|
||||
FROM alpine
|
||||
RUN apk --update --no-cache add ca-certificates
|
||||
WORKDIR /app/
|
||||
COPY --from=frontend_builder /app/templates ./templates
|
||||
COPY --from=frontend_builder /app/dist ./assets
|
||||
COPY --from=backend_builder /podsync/server .
|
||||
ENV ASSETS_PATH /app/assets
|
||||
ENV TEMPLATES_PATH /app/templates
|
||||
ENTRYPOINT ["/app/server"]
|
||||
@@ -58,5 +58,4 @@ services:
|
||||
- LE_EMAIL=pavlenko.maksym@gmail.com
|
||||
- LE_FQDN=podsync.net,www.podsync.net
|
||||
volumes:
|
||||
- /data/ssl:/etc/nginx/ssl
|
||||
- /data/podsync.conf:/etc/nginx/service.conf
|
||||
- /data/ssl:/etc/nginx/ssl
|
||||
@@ -18,8 +18,6 @@ type AppConfig struct {
|
||||
PostgresConnectionURL string `yaml:"postgresConnectionUrl"`
|
||||
RedisURL string `yaml:"redisUrl"`
|
||||
CookieSecret string `yaml:"cookieSecret"`
|
||||
AssetsPath string `yaml:"assetsPath"`
|
||||
TemplatesPath string `yaml:"templatesPath"`
|
||||
AWSAccessKey string `yaml:"awsAccessKey"`
|
||||
AWSAccessSecret string `yaml:"awsAccessSecret"`
|
||||
DynamoFeedsTableName string `yaml:"dynamoFeedsTableName"`
|
||||
@@ -47,8 +45,6 @@ func ReadConfiguration() (cfg *AppConfig, err error) {
|
||||
"postgresConnectionUrl": "POSTGRES_CONNECTION_URL",
|
||||
"redisUrl": "REDIS_CONNECTION_URL",
|
||||
"cookieSecret": "COOKIE_SECRET",
|
||||
"assetsPath": "ASSETS_PATH",
|
||||
"templatesPath": "TEMPLATES_PATH",
|
||||
"awsAccessKey": "AWS_ACCESS_KEY",
|
||||
"awsAccessSecret": "AWS_ACCESS_SECRET",
|
||||
"dynamoFeedsTableName": "DYNAMO_FEEDS_TABLE_NAME",
|
||||
|
||||
@@ -17,8 +17,6 @@ patreonSecret: "4"
|
||||
postgresConnectionUrl: "5"
|
||||
cookieSecret: "6"
|
||||
patreonRedirectUrl: "7"
|
||||
assetsPath: "8"
|
||||
templatesPath: "9"
|
||||
patreonWebhooksSecret: "10"
|
||||
dynamoFeedsTableName: "11"
|
||||
dynamoPledgesTableName: "12"
|
||||
@@ -43,8 +41,6 @@ func TestReadYaml(t *testing.T) {
|
||||
require.Equal(t, "5", cfg.PostgresConnectionURL)
|
||||
require.Equal(t, "6", cfg.CookieSecret)
|
||||
require.Equal(t, "7", cfg.PatreonRedirectURL)
|
||||
require.Equal(t, "8", cfg.AssetsPath)
|
||||
require.Equal(t, "9", cfg.TemplatesPath)
|
||||
require.Equal(t, "10", cfg.PatreonWebhooksSecret)
|
||||
require.Equal(t, "11", cfg.DynamoFeedsTableName)
|
||||
require.Equal(t, "12", cfg.DynamoPledgesTableName)
|
||||
@@ -63,8 +59,6 @@ func TestReadEnv(t *testing.T) {
|
||||
os.Setenv("POSTGRES_CONNECTION_URL", "55")
|
||||
os.Setenv("COOKIE_SECRET", "66")
|
||||
os.Setenv("PATREON_REDIRECT_URL", "77")
|
||||
os.Setenv("ASSETS_PATH", "88")
|
||||
os.Setenv("TEMPLATES_PATH", "99")
|
||||
os.Setenv("PATREON_WEBHOOKS_SECRET", "1010")
|
||||
os.Setenv("DYNAMO_FEEDS_TABLE_NAME", "1111")
|
||||
os.Setenv("DYNAMO_PLEDGES_TABLE_NAME", "1212")
|
||||
@@ -81,8 +75,6 @@ func TestReadEnv(t *testing.T) {
|
||||
require.Equal(t, "55", cfg.PostgresConnectionURL)
|
||||
require.Equal(t, "66", cfg.CookieSecret)
|
||||
require.Equal(t, "77", cfg.PatreonRedirectURL)
|
||||
require.Equal(t, "88", cfg.AssetsPath)
|
||||
require.Equal(t, "99", cfg.TemplatesPath)
|
||||
require.Equal(t, "1010", cfg.PatreonWebhooksSecret)
|
||||
require.Equal(t, "1111", cfg.DynamoFeedsTableName)
|
||||
require.Equal(t, "1212", cfg.DynamoPledgesTableName)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
@@ -51,18 +50,6 @@ func New(feed feedService, support patreonService, cfg *config.AppConfig) http.H
|
||||
store := sessions.NewCookieStore([]byte(cfg.CookieSecret))
|
||||
r.Use(sessions.Sessions("podsync", store))
|
||||
|
||||
// Static files + HTML
|
||||
|
||||
log.Printf("using assets path: %s", cfg.AssetsPath)
|
||||
if cfg.AssetsPath != "" {
|
||||
r.Static("/assets", cfg.AssetsPath)
|
||||
}
|
||||
|
||||
log.Printf("using templates path: %s", cfg.TemplatesPath)
|
||||
if cfg.TemplatesPath != "" {
|
||||
r.LoadHTMLGlob(path.Join(cfg.TemplatesPath, "*.html"))
|
||||
}
|
||||
|
||||
h := handler{
|
||||
feed: feed,
|
||||
patreon: support,
|
||||
@@ -84,11 +71,9 @@ func New(feed feedService, support patreonService, cfg *config.AppConfig) http.H
|
||||
|
||||
// Handlers
|
||||
|
||||
r.GET("/", h.index)
|
||||
r.GET("/login", h.login)
|
||||
r.GET("/logout", h.logout)
|
||||
r.GET("/patreon", h.patreonCallback)
|
||||
r.GET("/robots.txt", h.robots)
|
||||
|
||||
r.GET("/api/ping", h.ping)
|
||||
r.GET("/api/user", h.user)
|
||||
@@ -101,15 +86,6 @@ func New(feed feedService, support patreonService, cfg *config.AppConfig) http.H
|
||||
return r
|
||||
}
|
||||
|
||||
func (h handler) index(c *gin.Context) {
|
||||
identity, err := session.GetIdentity(c)
|
||||
if err != nil {
|
||||
identity = &api.Identity{}
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "index.html", identity)
|
||||
}
|
||||
|
||||
func (h handler) login(c *gin.Context) {
|
||||
state, err := session.SetState(c)
|
||||
if err != nil {
|
||||
@@ -167,13 +143,6 @@ func (h handler) patreonCallback(c *gin.Context) {
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
}
|
||||
|
||||
func (h handler) robots(c *gin.Context) {
|
||||
c.String(http.StatusOK, `User-agent: *
|
||||
Allow: /$
|
||||
Disallow: /
|
||||
Host: www.podsync.net`)
|
||||
}
|
||||
|
||||
func (h handler) ping(c *gin.Context) {
|
||||
c.String(http.StatusOK, "ok")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: handler.go
|
||||
|
||||
// Package handler is a generated GoMock package.
|
||||
package handler
|
||||
|
||||
import (
|
||||
@@ -30,59 +31,59 @@ func NewMockfeedService(ctrl *gomock.Controller) *MockfeedService {
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (_m *MockfeedService) EXPECT() *MockfeedServiceMockRecorder {
|
||||
return _m.recorder
|
||||
func (m *MockfeedService) EXPECT() *MockfeedServiceMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// CreateFeed mocks base method
|
||||
func (_m *MockfeedService) CreateFeed(req *api.CreateFeedRequest, identity *api.Identity) (string, error) {
|
||||
ret := _m.ctrl.Call(_m, "CreateFeed", req, identity)
|
||||
func (m *MockfeedService) CreateFeed(req *api.CreateFeedRequest, identity *api.Identity) (string, error) {
|
||||
ret := m.ctrl.Call(m, "CreateFeed", req, identity)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateFeed indicates an expected call of CreateFeed
|
||||
func (_mr *MockfeedServiceMockRecorder) CreateFeed(arg0, arg1 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "CreateFeed", reflect.TypeOf((*MockfeedService)(nil).CreateFeed), arg0, arg1)
|
||||
func (mr *MockfeedServiceMockRecorder) CreateFeed(req, identity interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateFeed", reflect.TypeOf((*MockfeedService)(nil).CreateFeed), req, identity)
|
||||
}
|
||||
|
||||
// BuildFeed mocks base method
|
||||
func (_m *MockfeedService) BuildFeed(hashID string) (*podcast.Podcast, error) {
|
||||
ret := _m.ctrl.Call(_m, "BuildFeed", hashID)
|
||||
func (m *MockfeedService) BuildFeed(hashID string) (*podcast.Podcast, error) {
|
||||
ret := m.ctrl.Call(m, "BuildFeed", hashID)
|
||||
ret0, _ := ret[0].(*podcast.Podcast)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// BuildFeed indicates an expected call of BuildFeed
|
||||
func (_mr *MockfeedServiceMockRecorder) BuildFeed(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "BuildFeed", reflect.TypeOf((*MockfeedService)(nil).BuildFeed), arg0)
|
||||
func (mr *MockfeedServiceMockRecorder) BuildFeed(hashID interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BuildFeed", reflect.TypeOf((*MockfeedService)(nil).BuildFeed), hashID)
|
||||
}
|
||||
|
||||
// GetMetadata mocks base method
|
||||
func (_m *MockfeedService) GetMetadata(hashId string) (*api.Metadata, error) {
|
||||
ret := _m.ctrl.Call(_m, "GetMetadata", hashId)
|
||||
func (m *MockfeedService) GetMetadata(hashId string) (*api.Metadata, error) {
|
||||
ret := m.ctrl.Call(m, "GetMetadata", hashId)
|
||||
ret0, _ := ret[0].(*api.Metadata)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetMetadata indicates an expected call of GetMetadata
|
||||
func (_mr *MockfeedServiceMockRecorder) GetMetadata(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetMetadata", reflect.TypeOf((*MockfeedService)(nil).GetMetadata), arg0)
|
||||
func (mr *MockfeedServiceMockRecorder) GetMetadata(hashId interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetadata", reflect.TypeOf((*MockfeedService)(nil).GetMetadata), hashId)
|
||||
}
|
||||
|
||||
// Downgrade mocks base method
|
||||
func (_m *MockfeedService) Downgrade(patronID string, featureLevel int) error {
|
||||
ret := _m.ctrl.Call(_m, "Downgrade", patronID, featureLevel)
|
||||
func (m *MockfeedService) Downgrade(patronID string, featureLevel int) error {
|
||||
ret := m.ctrl.Call(m, "Downgrade", patronID, featureLevel)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Downgrade indicates an expected call of Downgrade
|
||||
func (_mr *MockfeedServiceMockRecorder) Downgrade(arg0, arg1 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Downgrade", reflect.TypeOf((*MockfeedService)(nil).Downgrade), arg0, arg1)
|
||||
func (mr *MockfeedServiceMockRecorder) Downgrade(patronID, featureLevel interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Downgrade", reflect.TypeOf((*MockfeedService)(nil).Downgrade), patronID, featureLevel)
|
||||
}
|
||||
|
||||
// MockpatreonService is a mock of patreonService interface
|
||||
@@ -104,42 +105,42 @@ func NewMockpatreonService(ctrl *gomock.Controller) *MockpatreonService {
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (_m *MockpatreonService) EXPECT() *MockpatreonServiceMockRecorder {
|
||||
return _m.recorder
|
||||
func (m *MockpatreonService) EXPECT() *MockpatreonServiceMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Hook mocks base method
|
||||
func (_m *MockpatreonService) Hook(pledge *patreon_go.Pledge, event string) error {
|
||||
ret := _m.ctrl.Call(_m, "Hook", pledge, event)
|
||||
func (m *MockpatreonService) Hook(pledge *patreon_go.Pledge, event string) error {
|
||||
ret := m.ctrl.Call(m, "Hook", pledge, event)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Hook indicates an expected call of Hook
|
||||
func (_mr *MockpatreonServiceMockRecorder) Hook(arg0, arg1 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Hook", reflect.TypeOf((*MockpatreonService)(nil).Hook), arg0, arg1)
|
||||
func (mr *MockpatreonServiceMockRecorder) Hook(pledge, event interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Hook", reflect.TypeOf((*MockpatreonService)(nil).Hook), pledge, event)
|
||||
}
|
||||
|
||||
// GetFeatureLevelByID mocks base method
|
||||
func (_m *MockpatreonService) GetFeatureLevelByID(patronID string) int {
|
||||
ret := _m.ctrl.Call(_m, "GetFeatureLevelByID", patronID)
|
||||
func (m *MockpatreonService) GetFeatureLevelByID(patronID string) int {
|
||||
ret := m.ctrl.Call(m, "GetFeatureLevelByID", patronID)
|
||||
ret0, _ := ret[0].(int)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetFeatureLevelByID indicates an expected call of GetFeatureLevelByID
|
||||
func (_mr *MockpatreonServiceMockRecorder) GetFeatureLevelByID(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetFeatureLevelByID", reflect.TypeOf((*MockpatreonService)(nil).GetFeatureLevelByID), arg0)
|
||||
func (mr *MockpatreonServiceMockRecorder) GetFeatureLevelByID(patronID interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeatureLevelByID", reflect.TypeOf((*MockpatreonService)(nil).GetFeatureLevelByID), patronID)
|
||||
}
|
||||
|
||||
// GetFeatureLevelFromAmount mocks base method
|
||||
func (_m *MockpatreonService) GetFeatureLevelFromAmount(amount int) int {
|
||||
ret := _m.ctrl.Call(_m, "GetFeatureLevelFromAmount", amount)
|
||||
func (m *MockpatreonService) GetFeatureLevelFromAmount(amount int) int {
|
||||
ret := m.ctrl.Call(m, "GetFeatureLevelFromAmount", amount)
|
||||
ret0, _ := ret[0].(int)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetFeatureLevelFromAmount indicates an expected call of GetFeatureLevelFromAmount
|
||||
func (_mr *MockpatreonServiceMockRecorder) GetFeatureLevelFromAmount(arg0 interface{}) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetFeatureLevelFromAmount", reflect.TypeOf((*MockpatreonService)(nil).GetFeatureLevelFromAmount), arg0)
|
||||
func (mr *MockpatreonServiceMockRecorder) GetFeatureLevelFromAmount(amount interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeatureLevelFromAmount", reflect.TypeOf((*MockpatreonService)(nil).GetFeatureLevelFromAmount), amount)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ import (
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
itunes "github.com/mxpv/podcast"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mxpv/podsync/pkg/api"
|
||||
"github.com/mxpv/podsync/pkg/config"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var cfg = &config.AppConfig{}
|
||||
|
||||
Reference in New Issue
Block a user