diff --git a/.gitignore b/.gitignore index 7e18ad6..12cc8b8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,9 +19,8 @@ debug.test *.db *.lock /config.* -/handlers/static.go -/handlers/tmpls/tmpls.go -/store/main.db +/internal/handlers/static.go +/internal/handlers/tmpls/tmpls.go /releases -/data -docker_releases/ +/docker_releases +data diff --git a/.travis.yml b/.travis.yml index d78e56f..9a238ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ install: - npm install script: - make - - goveralls -service=travis-ci -ignore="handlers/static.go,handlers/tmpls/tmpls.go" + - goveralls -service=travis-ci -ignore="internal/handlers/static.go,internal/handlers/tmpls/tmpls.go" - make buildDockerImage - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" && docker push mxschmitt/golang_url_shortener && docker push mxschmitt/golang_url_shortener:arm; fi' + - 'if [[ "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" = "master" ]]; then docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" && docker push mxschmitt/golang_url_shortener && docker push mxschmitt/golang_url_shortener:arm; fi' deploy: provider: bintray user: mxschmitt diff --git a/Makefile b/Makefile index d39b832..400079c 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ runUnitTests: go test -v ./... buildNodeFrontend: - cd static && yarn install - cd static && yarn build - cd static && rm build/static/**/*.map + cd web && yarn install + cd web && yarn build + cd web && rm build/static/**/*.map embedFrontend: - cd handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.html . - cd handlers && esc -o static.go -pkg handlers -prefix ../static/build ../static/build + cd internal/handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.html . + cd internal/handlers && esc -o static.go -pkg handlers -prefix ../../web/build ../../web/build getCMDDependencies: go get -v github.com/mattn/goveralls @@ -23,13 +23,13 @@ getGoDependencies: buildProject: rm -rf releases mkdir releases - gox -output="releases/{{.Dir}}_{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="linux/amd64 linux/arm windows/amd64 windows/386" -ldflags="-X github.com/mxschmitt/golang-url-shortener/util.ldFlagNodeJS=`node --version` -X github.com/mxschmitt/golang-url-shortener/util.ldFlagCommit=`git rev-parse HEAD` -X github.com/mxschmitt/golang-url-shortener/util.ldFlagYarn=`yarn --version` -X github.com/mxschmitt/golang-url-shortener/util.ldFlagCompilationTime=`TZ=UTC date +%Y-%m-%dT%H:%M:%S+0000`" - find releases -maxdepth 1 -mindepth 1 -type d -exec cp build/config.yaml {} \; + gox -output="releases/{{.Dir}}_{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="linux/amd64 linux/arm windows/amd64 windows/386" -ldflags="-X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagNodeJS=`node --version` -X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagCommit=`git rev-parse HEAD` -X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagYarn=`yarn --version` -X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagCompilationTime=`TZ=UTC date +%Y-%m-%dT%H:%M:%S+0000`" ./cmd/golang-url-shortener + find releases -maxdepth 1 -mindepth 1 -type d -exec cp config/example.yaml {} \; find releases -maxdepth 1 -mindepth 1 -type d -exec tar -cvjf {}.tar.bz2 {} \; buildDockerImage: rm -rf docker_releases mkdir docker_releases - CGO_ENABLED=0 gox -output="docker_releases/{{.Dir}}_{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="linux/amd64 linux/arm" -ldflags="-X github.com/mxschmitt/golang-url-shortener/util.ldFlagNodeJS=`node --version` -X github.com/mxschmitt/golang-url-shortener/util.ldFlagCommit=`git rev-parse HEAD` -X github.com/mxschmitt/golang-url-shortener/util.ldFlagYarn=`yarn --version` -X github.com/mxschmitt/golang-url-shortener/util.ldFlagCompilationTime=`TZ=UTC date +%Y-%m-%dT%H:%M:%S+0000`" - docker build -t mxschmitt/golang_url_shortener:arm -f Dockerfile.arm . - docker build -t mxschmitt/golang_url_shortener -f Dockerfile.amd64 . + CGO_ENABLED=0 gox -output="docker_releases/{{.Dir}}_{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="linux/amd64 linux/arm" -ldflags="-X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagNodeJS=`node --version` -X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagCommit=`git rev-parse HEAD` -X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagYarn=`yarn --version` -X github.com/mxschmitt/golang-url-shortener/internal/util.ldFlagCompilationTime=`TZ=UTC date +%Y-%m-%dT%H:%M:%S+0000`" ./cmd/golang-url-shortener + docker build -t mxschmitt/golang_url_shortener:arm -f build/Dockerfile.arm . + docker build -t mxschmitt/golang_url_shortener -f build/Dockerfile.amd64 . diff --git a/Dockerfile.amd64 b/build/Dockerfile.amd64 similarity index 100% rename from Dockerfile.amd64 rename to build/Dockerfile.amd64 diff --git a/Dockerfile.arm b/build/Dockerfile.arm similarity index 100% rename from Dockerfile.arm rename to build/Dockerfile.arm diff --git a/main.go b/cmd/golang-url-shortener/main.go similarity index 88% rename from main.go rename to cmd/golang-url-shortener/main.go index 8bbfb86..d1d5dbd 100644 --- a/main.go +++ b/cmd/golang-url-shortener/main.go @@ -4,9 +4,9 @@ import ( "os" "os/signal" - "github.com/mxschmitt/golang-url-shortener/handlers" - "github.com/mxschmitt/golang-url-shortener/stores" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/handlers" + "github.com/mxschmitt/golang-url-shortener/internal/stores" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/pkg/errors" "github.com/shiena/ansicolor" "github.com/sirupsen/logrus" diff --git a/main_test.go b/cmd/golang-url-shortener/main_test.go similarity index 91% rename from main_test.go rename to cmd/golang-url-shortener/main_test.go index 7958e24..102cf75 100644 --- a/main_test.go +++ b/cmd/golang-url-shortener/main_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/util" ) func TestInitShortener(t *testing.T) { diff --git a/build/config.yaml b/config/example.yaml similarity index 100% rename from build/config.yaml rename to config/example.yaml diff --git a/docker-compose.yml b/deployments/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to deployments/docker-compose.yml diff --git a/handlers/auth.go b/internal/handlers/auth.go similarity index 97% rename from handlers/auth.go rename to internal/handlers/auth.go index 2b7d20b..8c066e4 100644 --- a/handlers/auth.go +++ b/internal/handlers/auth.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - "github.com/mxschmitt/golang-url-shortener/handlers/auth" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/handlers/auth" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/sirupsen/logrus" jwt "github.com/dgrijalva/jwt-go" diff --git a/handlers/auth/auth.go b/internal/handlers/auth/auth.go similarity index 98% rename from handlers/auth/auth.go rename to internal/handlers/auth/auth.go index c42356b..8e3e8f7 100644 --- a/handlers/auth/auth.go +++ b/internal/handlers/auth/auth.go @@ -10,7 +10,7 @@ import ( jwt "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/handlers/auth/github.go b/internal/handlers/auth/github.go similarity index 96% rename from handlers/auth/github.go rename to internal/handlers/auth/github.go index 7c63e47..41eed81 100644 --- a/handlers/auth/github.go +++ b/internal/handlers/auth/github.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/sirupsen/logrus" "golang.org/x/oauth2/github" diff --git a/handlers/auth/google.go b/internal/handlers/auth/google.go similarity index 96% rename from handlers/auth/google.go rename to internal/handlers/auth/google.go index f2d1055..1a60466 100644 --- a/handlers/auth/google.go +++ b/internal/handlers/auth/google.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/pkg/errors" "golang.org/x/oauth2" "golang.org/x/oauth2/google" diff --git a/handlers/auth/microsoft.go b/internal/handlers/auth/microsoft.go similarity index 96% rename from handlers/auth/microsoft.go rename to internal/handlers/auth/microsoft.go index 546402f..09efbe4 100644 --- a/handlers/auth/microsoft.go +++ b/internal/handlers/auth/microsoft.go @@ -7,7 +7,7 @@ import ( "golang.org/x/oauth2/microsoft" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/sirupsen/logrus" "github.com/pkg/errors" diff --git a/handlers/auth_test.go b/internal/handlers/auth_test.go similarity index 95% rename from handlers/auth_test.go rename to internal/handlers/auth_test.go index 4fbad9c..9a842b9 100644 --- a/handlers/auth_test.go +++ b/internal/handlers/auth_test.go @@ -11,9 +11,9 @@ import ( jwt "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" - "github.com/mxschmitt/golang-url-shortener/handlers/auth" - "github.com/mxschmitt/golang-url-shortener/stores" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/handlers/auth" + "github.com/mxschmitt/golang-url-shortener/internal/stores" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/pkg/errors" ) diff --git a/handlers/handlers.go b/internal/handlers/handlers.go similarity index 93% rename from handlers/handlers.go rename to internal/handlers/handlers.go index 189936a..b8eb537 100644 --- a/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -9,9 +9,9 @@ import ( "github.com/sirupsen/logrus" "github.com/gin-gonic/gin" - "github.com/mxschmitt/golang-url-shortener/handlers/tmpls" - "github.com/mxschmitt/golang-url-shortener/stores" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/handlers/tmpls" + "github.com/mxschmitt/golang-url-shortener/internal/stores" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/pkg/errors" ) @@ -145,13 +145,14 @@ func (h *Handler) setHandlers() error { } } protected := h.engine.Group("/api/v1/protected") - if util.GetConfig().AuthBackend == "oauth" { - logrus.Info("Using OAuth auth backend") + switch util.GetConfig().AuthBackend { + case "oauth": + logrus.Info("Using OAuth auth backend: oauth") protected.Use(h.oAuthMiddleware) - } else if util.GetConfig().AuthBackend == "proxy" { - logrus.Info("Using proxy auth backend") + case "proxy": + logrus.Info("Using OAuth auth backend: proxy") protected.Use(h.proxyAuthMiddleware) - } else { + default: logrus.Fatalf("Auth backend method '%s' is not recognized", util.GetConfig().AuthBackend) } protected.POST("/create", h.handleCreate) diff --git a/handlers/public.go b/internal/handlers/public.go similarity index 96% rename from handlers/public.go rename to internal/handlers/public.go index 0d0159b..81e1510 100644 --- a/handlers/public.go +++ b/internal/handlers/public.go @@ -12,9 +12,9 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/mxschmitt/golang-url-shortener/handlers/auth" - "github.com/mxschmitt/golang-url-shortener/stores/shared" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/handlers/auth" + "github.com/mxschmitt/golang-url-shortener/internal/stores/shared" + "github.com/mxschmitt/golang-url-shortener/internal/util" "golang.org/x/crypto/bcrypt" ) diff --git a/handlers/public_test.go b/internal/handlers/public_test.go similarity index 98% rename from handlers/public_test.go rename to internal/handlers/public_test.go index 2b55a98..cfab783 100644 --- a/handlers/public_test.go +++ b/internal/handlers/public_test.go @@ -11,8 +11,8 @@ import ( "testing" "github.com/gin-gonic/gin" - "github.com/mxschmitt/golang-url-shortener/stores" - "github.com/mxschmitt/golang-url-shortener/stores/shared" + "github.com/mxschmitt/golang-url-shortener/internal/stores" + "github.com/mxschmitt/golang-url-shortener/internal/stores/shared" ) const testURL = "https://www.google.de/" diff --git a/handlers/test.yaml b/internal/handlers/test.yaml similarity index 100% rename from handlers/test.yaml rename to internal/handlers/test.yaml diff --git a/handlers/tmpls/protected.html b/internal/handlers/tmpls/protected.html similarity index 100% rename from handlers/tmpls/protected.html rename to internal/handlers/tmpls/protected.html diff --git a/handlers/tmpls/token.html b/internal/handlers/tmpls/token.html similarity index 100% rename from handlers/tmpls/token.html rename to internal/handlers/tmpls/token.html diff --git a/stores/boltdb/boltdb.go b/internal/stores/boltdb/boltdb.go similarity index 98% rename from stores/boltdb/boltdb.go rename to internal/stores/boltdb/boltdb.go index 3c5f401..99fa9e8 100644 --- a/stores/boltdb/boltdb.go +++ b/internal/stores/boltdb/boltdb.go @@ -6,7 +6,7 @@ import ( "time" "github.com/boltdb/bolt" - "github.com/mxschmitt/golang-url-shortener/stores/shared" + "github.com/mxschmitt/golang-url-shortener/internal/stores/shared" "github.com/pkg/errors" ) diff --git a/stores/redis/redis.go b/internal/stores/redis/redis.go similarity index 99% rename from stores/redis/redis.go rename to internal/stores/redis/redis.go index 391698e..18d92c9 100644 --- a/stores/redis/redis.go +++ b/internal/stores/redis/redis.go @@ -6,7 +6,7 @@ import ( "time" "github.com/go-redis/redis" - "github.com/mxschmitt/golang-url-shortener/stores/shared" + "github.com/mxschmitt/golang-url-shortener/internal/stores/shared" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/stores/shared/shared.go b/internal/stores/shared/shared.go similarity index 100% rename from stores/shared/shared.go rename to internal/stores/shared/shared.go diff --git a/stores/sqlite/sqlite.go b/internal/stores/sqlite/sqlite.go similarity index 100% rename from stores/sqlite/sqlite.go rename to internal/stores/sqlite/sqlite.go diff --git a/stores/store.go b/internal/stores/store.go similarity index 95% rename from stores/store.go rename to internal/stores/store.go index 2865e31..c86cfaa 100644 --- a/stores/store.go +++ b/internal/stores/store.go @@ -12,10 +12,10 @@ import ( "unicode" "github.com/asaskevich/govalidator" - "github.com/mxschmitt/golang-url-shortener/stores/boltdb" - "github.com/mxschmitt/golang-url-shortener/stores/redis" - "github.com/mxschmitt/golang-url-shortener/stores/shared" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/stores/boltdb" + "github.com/mxschmitt/golang-url-shortener/internal/stores/redis" + "github.com/mxschmitt/golang-url-shortener/internal/stores/shared" + "github.com/mxschmitt/golang-url-shortener/internal/util" "github.com/pborman/uuid" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/stores/store_test.go b/internal/stores/store_test.go similarity index 96% rename from stores/store_test.go rename to internal/stores/store_test.go index a9f09bb..489d58d 100644 --- a/stores/store_test.go +++ b/internal/stores/store_test.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" - "github.com/mxschmitt/golang-url-shortener/stores/shared" + "github.com/mxschmitt/golang-url-shortener/internal/stores/shared" - "github.com/mxschmitt/golang-url-shortener/util" + "github.com/mxschmitt/golang-url-shortener/internal/util" ) var testData = struct { diff --git a/util/config.go b/internal/util/config.go similarity index 100% rename from util/config.go rename to internal/util/config.go diff --git a/util/config_test.go b/internal/util/config_test.go similarity index 100% rename from util/config_test.go rename to internal/util/config_test.go diff --git a/util/private.go b/internal/util/private.go similarity index 100% rename from util/private.go rename to internal/util/private.go diff --git a/util/private_test.go b/internal/util/private_test.go similarity index 100% rename from util/private_test.go rename to internal/util/private_test.go diff --git a/util/test.yaml b/internal/util/test.yaml similarity index 100% rename from util/test.yaml rename to internal/util/test.yaml diff --git a/util/version.go b/internal/util/version.go similarity index 100% rename from util/version.go rename to internal/util/version.go diff --git a/static/.gitignore b/web/.gitignore similarity index 100% rename from static/.gitignore rename to web/.gitignore diff --git a/static/package.json b/web/package.json similarity index 100% rename from static/package.json rename to web/package.json diff --git a/static/public/favicon.ico b/web/public/favicon.ico similarity index 100% rename from static/public/favicon.ico rename to web/public/favicon.ico diff --git a/static/public/images/proxy_user.png b/web/public/images/proxy_user.png similarity index 100% rename from static/public/images/proxy_user.png rename to web/public/images/proxy_user.png diff --git a/static/public/images/setting-up-sharex/import-url-shortener.png b/web/public/images/setting-up-sharex/import-url-shortener.png similarity index 100% rename from static/public/images/setting-up-sharex/import-url-shortener.png rename to web/public/images/setting-up-sharex/import-url-shortener.png diff --git a/static/public/images/setting-up-sharex/open-destination-settings.png b/web/public/images/setting-up-sharex/open-destination-settings.png similarity index 100% rename from static/public/images/setting-up-sharex/open-destination-settings.png rename to web/public/images/setting-up-sharex/open-destination-settings.png diff --git a/static/public/images/setting-up-sharex/set-default-shortener.png b/web/public/images/setting-up-sharex/set-default-shortener.png similarity index 100% rename from static/public/images/setting-up-sharex/set-default-shortener.png rename to web/public/images/setting-up-sharex/set-default-shortener.png diff --git a/static/public/index.html b/web/public/index.html similarity index 100% rename from static/public/index.html rename to web/public/index.html diff --git a/static/src/About/About.js b/web/src/About/About.js similarity index 100% rename from static/src/About/About.js rename to web/src/About/About.js diff --git a/static/src/Card/Card.js b/web/src/Card/Card.js similarity index 100% rename from static/src/Card/Card.js rename to web/src/Card/Card.js diff --git a/static/src/Home/Home.css b/web/src/Home/Home.css similarity index 100% rename from static/src/Home/Home.css rename to web/src/Home/Home.css diff --git a/static/src/Home/Home.js b/web/src/Home/Home.js similarity index 100% rename from static/src/Home/Home.js rename to web/src/Home/Home.js diff --git a/static/src/Lookup/Lookup.js b/web/src/Lookup/Lookup.js similarity index 100% rename from static/src/Lookup/Lookup.js rename to web/src/Lookup/Lookup.js diff --git a/static/src/Recent/Recent.js b/web/src/Recent/Recent.js similarity index 100% rename from static/src/Recent/Recent.js rename to web/src/Recent/Recent.js diff --git a/static/src/ShareX/ShareX.css b/web/src/ShareX/ShareX.css similarity index 100% rename from static/src/ShareX/ShareX.css rename to web/src/ShareX/ShareX.css diff --git a/static/src/ShareX/ShareX.js b/web/src/ShareX/ShareX.js similarity index 100% rename from static/src/ShareX/ShareX.js rename to web/src/ShareX/ShareX.js diff --git a/static/src/Visitors/Visitors.js b/web/src/Visitors/Visitors.js similarity index 100% rename from static/src/Visitors/Visitors.js rename to web/src/Visitors/Visitors.js diff --git a/static/src/index.js b/web/src/index.js similarity index 100% rename from static/src/index.js rename to web/src/index.js diff --git a/static/src/util/util.js b/web/src/util/util.js similarity index 100% rename from static/src/util/util.js rename to web/src/util/util.js