* 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
|
*.db
|
||||||
*.lock
|
*.lock
|
||||||
/config.*
|
/config.*
|
||||||
/handlers/static.go
|
/internal/handlers/static.go
|
||||||
/handlers/tmpls/tmpls.go
|
/internal/handlers/tmpls/tmpls.go
|
||||||
/store/main.db
|
|
||||||
/releases
|
/releases
|
||||||
/data
|
/docker_releases
|
||||||
docker_releases/
|
data
|
||||||
|
|
|
@ -11,9 +11,9 @@ install:
|
||||||
- npm install
|
- npm install
|
||||||
script:
|
script:
|
||||||
- make
|
- 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
|
- 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:
|
deploy:
|
||||||
provider: bintray
|
provider: bintray
|
||||||
user: mxschmitt
|
user: mxschmitt
|
||||||
|
|
20
Makefile
|
@ -4,13 +4,13 @@ runUnitTests:
|
||||||
go test -v ./...
|
go test -v ./...
|
||||||
|
|
||||||
buildNodeFrontend:
|
buildNodeFrontend:
|
||||||
cd static && yarn install
|
cd web && yarn install
|
||||||
cd static && yarn build
|
cd web && yarn build
|
||||||
cd static && rm build/static/**/*.map
|
cd web && rm build/static/**/*.map
|
||||||
|
|
||||||
embedFrontend:
|
embedFrontend:
|
||||||
cd handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.html .
|
cd internal/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 && esc -o static.go -pkg handlers -prefix ../../web/build ../../web/build
|
||||||
|
|
||||||
getCMDDependencies:
|
getCMDDependencies:
|
||||||
go get -v github.com/mattn/goveralls
|
go get -v github.com/mattn/goveralls
|
||||||
|
@ -23,13 +23,13 @@ getGoDependencies:
|
||||||
buildProject:
|
buildProject:
|
||||||
rm -rf releases
|
rm -rf releases
|
||||||
mkdir 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`"
|
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 build/config.yaml {} \;
|
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 {} \;
|
find releases -maxdepth 1 -mindepth 1 -type d -exec tar -cvjf {}.tar.bz2 {} \;
|
||||||
|
|
||||||
buildDockerImage:
|
buildDockerImage:
|
||||||
rm -rf docker_releases
|
rm -rf docker_releases
|
||||||
mkdir 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`"
|
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 Dockerfile.arm .
|
docker build -t mxschmitt/golang_url_shortener:arm -f build/Dockerfile.arm .
|
||||||
docker build -t mxschmitt/golang_url_shortener -f Dockerfile.amd64 .
|
docker build -t mxschmitt/golang_url_shortener -f build/Dockerfile.amd64 .
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"github.com/mxschmitt/golang-url-shortener/handlers"
|
"github.com/mxschmitt/golang-url-shortener/internal/handlers"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores"
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/shiena/ansicolor"
|
"github.com/shiena/ansicolor"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInitShortener(t *testing.T) {
|
func TestInitShortener(t *testing.T) {
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/mxschmitt/golang-url-shortener/handlers/auth"
|
"github.com/mxschmitt/golang-url-shortener/internal/handlers/auth"
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
jwt "github.com/dgrijalva/jwt-go"
|
|
@ -10,7 +10,7 @@ import (
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
jwt "github.com/dgrijalva/jwt-go"
|
||||||
"github.com/gin-gonic/contrib/sessions"
|
"github.com/gin-gonic/contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"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/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"golang.org/x/oauth2/github"
|
"golang.org/x/oauth2/github"
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"golang.org/x/oauth2/microsoft"
|
"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/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
|
@ -11,9 +11,9 @@ import (
|
||||||
|
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
jwt "github.com/dgrijalva/jwt-go"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/mxschmitt/golang-url-shortener/handlers/auth"
|
"github.com/mxschmitt/golang-url-shortener/internal/handlers/auth"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores"
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/mxschmitt/golang-url-shortener/handlers/tmpls"
|
"github.com/mxschmitt/golang-url-shortener/internal/handlers/tmpls"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores"
|
||||||
"github.com/mxschmitt/golang-url-shortener/util"
|
"github.com/mxschmitt/golang-url-shortener/internal/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -145,13 +145,14 @@ func (h *Handler) setHandlers() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected := h.engine.Group("/api/v1/protected")
|
protected := h.engine.Group("/api/v1/protected")
|
||||||
if util.GetConfig().AuthBackend == "oauth" {
|
switch util.GetConfig().AuthBackend {
|
||||||
logrus.Info("Using OAuth auth backend")
|
case "oauth":
|
||||||
|
logrus.Info("Using OAuth auth backend: oauth")
|
||||||
protected.Use(h.oAuthMiddleware)
|
protected.Use(h.oAuthMiddleware)
|
||||||
} else if util.GetConfig().AuthBackend == "proxy" {
|
case "proxy":
|
||||||
logrus.Info("Using proxy auth backend")
|
logrus.Info("Using OAuth auth backend: proxy")
|
||||||
protected.Use(h.proxyAuthMiddleware)
|
protected.Use(h.proxyAuthMiddleware)
|
||||||
} else {
|
default:
|
||||||
logrus.Fatalf("Auth backend method '%s' is not recognized", util.GetConfig().AuthBackend)
|
logrus.Fatalf("Auth backend method '%s' is not recognized", util.GetConfig().AuthBackend)
|
||||||
}
|
}
|
||||||
protected.POST("/create", h.handleCreate)
|
protected.POST("/create", h.handleCreate)
|
|
@ -12,9 +12,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/mxschmitt/golang-url-shortener/handlers/auth"
|
"github.com/mxschmitt/golang-url-shortener/internal/handlers/auth"
|
||||||
"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"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores/shared"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testURL = "https://www.google.de/"
|
const testURL = "https://www.google.de/"
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"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"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis"
|
"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/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
|
@ -12,10 +12,10 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/asaskevich/govalidator"
|
"github.com/asaskevich/govalidator"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores/boltdb"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores/boltdb"
|
||||||
"github.com/mxschmitt/golang-url-shortener/stores/redis"
|
"github.com/mxschmitt/golang-url-shortener/internal/stores/redis"
|
||||||
"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"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
|
@ -6,9 +6,9 @@ import (
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"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 {
|
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 |