* 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
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
20
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 .
|
||||
|
|
|
@ -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"
|
|
@ -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) {
|
|
@ -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"
|
|
@ -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"
|
||||
)
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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)
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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/"
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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"
|
||||
)
|
|
@ -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"
|
|
@ -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 {
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |