Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 3ebe9d0

Browse files
authored
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
1 parent 454199a commit 3ebe9d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+51
-51
lines changed

.gitignore

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ debug.test
1919
*.db
2020
*.lock
2121
/config.*
22-
/handlers/static.go
23-
/handlers/tmpls/tmpls.go
24-
/store/main.db
22+
/internal/handlers/static.go
23+
/internal/handlers/tmpls/tmpls.go
2524
/releases
26-
/data
27-
docker_releases/
25+
/docker_releases
26+
data

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ install:
1111
- npm install
1212
script:
1313
- make
14-
- goveralls -service=travis-ci -ignore="handlers/static.go,handlers/tmpls/tmpls.go"
14+
- goveralls -service=travis-ci -ignore="internal/handlers/static.go,internal/handlers/tmpls/tmpls.go"
1515
- make buildDockerImage
16-
- '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'
16+
- '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'
1717
deploy:
1818
provider: bintray
1919
user: mxschmitt

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ runUnitTests:
44
go test -v ./...
55

66
buildNodeFrontend:
7-
cd static && yarn install
8-
cd static && yarn build
9-
cd static && rm build/static/**/*.map
7+
cd web && yarn install
8+
cd web && yarn build
9+
cd web && rm build/static/**/*.map
1010

1111
embedFrontend:
12-
cd handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.html .
13-
cd handlers && esc -o static.go -pkg handlers -prefix ../static/build ../static/build
12+
cd internal/handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.html .
13+
cd internal/handlers && esc -o static.go -pkg handlers -prefix ../../web/build ../../web/build
1414

1515
getCMDDependencies:
1616
go get -v github.com/mattn/goveralls
@@ -23,13 +23,13 @@ getGoDependencies:
2323
buildProject:
2424
rm -rf releases
2525
mkdir releases
26-
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`"
27-
find releases -maxdepth 1 -mindepth 1 -type d -exec cp build/config.yaml {} \;
26+
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
27+
find releases -maxdepth 1 -mindepth 1 -type d -exec cp config/example.yaml {} \;
2828
find releases -maxdepth 1 -mindepth 1 -type d -exec tar -cvjf {}.tar.bz2 {} \;
2929

3030
buildDockerImage:
3131
rm -rf docker_releases
3232
mkdir docker_releases
33-
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`"
34-
docker build -t mxschmitt/golang_url_shortener:arm -f Dockerfile.arm .
35-
docker build -t mxschmitt/golang_url_shortener -f Dockerfile.amd64 .
33+
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
34+
docker build -t mxschmitt/golang_url_shortener:arm -f build/Dockerfile.arm .
35+
docker build -t mxschmitt/golang_url_shortener -f build/Dockerfile.amd64 .
File renamed without changes.
File renamed without changes.

main.go renamed to cmd/golang-url-shortener/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"os"
55
"os/signal"
66

7-
"github.com/mxschmitt/golang-url-shortener/handlers"
8-
"github.com/mxschmitt/golang-url-shortener/stores"
9-
"github.com/mxschmitt/golang-url-shortener/util"
7+
"github.com/mxschmitt/golang-url-shortener/internal/handlers"
8+
"github.com/mxschmitt/golang-url-shortener/internal/stores"
9+
"github.com/mxschmitt/golang-url-shortener/internal/util"
1010
"github.com/pkg/errors"
1111
"github.com/shiena/ansicolor"
1212
"github.com/sirupsen/logrus"

main_test.go renamed to cmd/golang-url-shortener/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/mxschmitt/golang-url-shortener/util"
9+
"github.com/mxschmitt/golang-url-shortener/internal/util"
1010
)
1111

1212
func TestInitShortener(t *testing.T) {
File renamed without changes.
File renamed without changes.

handlers/auth.go renamed to internal/handlers/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"net/http"
66

7-
"github.com/mxschmitt/golang-url-shortener/handlers/auth"
8-
"github.com/mxschmitt/golang-url-shortener/util"
7+
"github.com/mxschmitt/golang-url-shortener/internal/handlers/auth"
8+
"github.com/mxschmitt/golang-url-shortener/internal/util"
99
"github.com/sirupsen/logrus"
1010

1111
jwt "github.com/dgrijalva/jwt-go"

0 commit comments

Comments
 (0)