Refactored project layout (fix: #109) (#111)

* Reworked project layout

* adjusted Makefile for new folder structure

* fixed path errors

* Fixed test import paths

* fixes

* only pushing image to the docker hub if the branch is master
This commit is contained in:
Max Schmitt 2018-05-25 23:48:23 +02:00 committed by GitHub
parent 454199ad9e
commit 3ebe9d042f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 51 additions and 51 deletions

9
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -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 .

View File

@ -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"

View File

@ -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) {

View File

@ -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"

View File

@ -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"
)

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"
)

View File

@ -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)

View File

@ -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"
)

View File

@ -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/"

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"

View File

@ -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 {

View File

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB