FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added unit tests, refactoring · jhenbertgit/Gokapi@abec640 · GitHub

Repository navigation

Commit abec640

Browse files
committed
Added unit tests, refactoring
1 parent 1a47cbc commit abec640

61 files changed

Lines changed: 632 additions & 181 deletions

Some content is hidden

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

‎.github/workflows/test-code.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ jobs:
1212
- uses: actions/setup-go@v2
1313
with:
1414
go-version: '^1.16.0'
15-
- run: go test
15+
- run: go test ./... --tags=test

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ config/
22
data/
33
.idea/
44
Gokapi
5-
test/

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN cd /compile && go mod download
1010

1111
COPY . /compile
1212

13-
RUN cd /compile && go generate && CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/internal/environment.IsDocker=true' -X 'Gokapi/internal/environment.Builder=Project Docker File' -X 'Gokapi/internal/environment.BuildTime=$(date)'" -o /compile/gokapi
13+
RUN cd /compile && go generate Gokapi/cmd/gokapi && CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/internal/environment.IsDocker=true' -X 'Gokapi/internal/environment.Builder=Project Docker File' -X 'Gokapi/internal/environment.BuildTime=$(date)'" -o /compile/gokapi Gokapi/cmd/gokapi
1414

1515
FROM alpine:3.13
1616

‎Main_test.go‎

Lines changed: 0 additions & 133 deletions
This file was deleted.

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Download Link![image](https://user-images.githubusercontent.com/1593467/11347760
2929

3030
### Bare Metal
3131

32-
Simply download the latest release for your platform and execute the binary (recommended). If you want to compile the source yourself, clone this repository and execute `go build`.
32+
Simply download the latest release for your platform and execute the binary (recommended). If you want to compile the source yourself, clone this repository and execute `go build Gokapi/cmd/gokapi` (requires Go 1.16+).
3333

3434
### Docker
3535

@@ -94,7 +94,7 @@ By default, all files are included in the executable. If you want to change the
9494
* Copy either the folder `static`, `templates` or both from the `web` folder to the directory where the executable is located
9595
* Make changes to the folders. `static` contains images, CSS files and JavaScript. `templates` contains the HTML code.
9696
* Restart the server. If the folders exist, the server will use the local files instead of the embedded files
97-
* Optional: To embed the files permanently, the executable needs to be recompiled with `go build`.
97+
* Optional: To embed the files permanently, copy the modified files back to the original folders and recompiled with `go build Gokapi/cmd/gokapi`.
9898

9999

100100
## Contributors

‎build/entrypoint.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ set -e
66
targets=${@-"darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 windows/amd64 windows/386"}
77

88
cd /usr/src/myapp
9-
go generate
9+
go generate Gokapi/cmd/gokapi
1010

1111
for target in $targets; do
1212
os="$(echo $target | cut -d '/' -f1)"
1313
arch="$(echo $target | cut -d '/' -f2)"
14-
output=".release/gokapi-${os}_${arch}"
14+
output="build/gokapi-${os}_${arch}"
1515
if [ $os = "windows" ]; then
1616
output+='.exe'
1717
fi
1818

1919
echo "----> Building project for: $target"
20-
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/internal/environment.Builder=Github Release Builder' -X 'Gokapi/internal/environment.BuildTime=$(date)'" -o $output
20+
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/internal/environment.Builder=Github Release Builder' -X 'Gokapi/internal/environment.BuildTime=$(date)'" -o $output Gokapi/cmd/gokapi
2121
zip -j $output.zip $output > /dev/null
2222
rm $output
2323
done

‎build/setVersionTemplate.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
#Called by go generate
33
#Sets the version number in the template automatically
4-
sed -i 's/{{define "version"}}.*{{end}}/{{define "version"}}'$1'{{end}}/g' ./web/templates/string_constants.tmpl
4+
sed -i 's/{{define "version"}}.*{{end}}/{{define "version"}}'$1'{{end}}/g' ../../internal/webserver/web/templates/string_constants.tmpl

Main.go renamed to cmd/gokapi/Main.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"Gokapi/internal/environment"
1010
"Gokapi/internal/storage"
1111
"Gokapi/internal/webserver"
12-
"embed"
1312
"fmt"
1413
"math/rand"
1514
"os"
@@ -20,7 +19,7 @@ import (
2019
// The go generate call below needs to be modified as well
2120
const Version = "1.1.4-dev"
2221

23-
//go:generate sh "./build/setVersionTemplate.sh" "1.1.4-dev"
22+
//go:generate sh "../../build/setVersionTemplate.sh" "1.1.4-dev"
2423

2524
// Main routine that is called on startup
2625
func main() {
@@ -31,7 +30,7 @@ func main() {
3130
configuration.Load()
3231
checkArguments()
3332
go storage.CleanUp(true)
34-
webserver.Start(&StaticFolderEmbedded, &TemplateFolderEmbedded, true)
33+
webserver.Start()
3534
}
3635

3736
// Checks for command line arguments that have to be parsed before loading the configuration
@@ -59,16 +58,6 @@ func checkArguments() {
5958
}
6059
}
6160

62-
// StaticFolderEmbedded is the embedded version of the "static" folder
63-
// This contains JS files, CSS, images etc
64-
//go:embed web/static
65-
var StaticFolderEmbedded embed.FS
66-
67-
// TemplateFolderEmbedded is the embedded version of the "templates" folder
68-
// This contains templates that Gokapi uses for creating the HTML output
69-
//go:embed web/templates
70-
var TemplateFolderEmbedded embed.FS
71-
7261
// ASCII art logo
7362
const logo = `
7463
██████  ██████  ██  ██  █████  ██████  ██ 

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Gokapi
33
go 1.16
44

55
require (
6+
github.com/otiai10/copy v1.5.1
67
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
78
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
89
)

‎go.sum‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
7-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1+
github.com/otiai10/copy v1.5.1 h1:a/cs2E1/1V0az8K5nblbl+ymEa4E11AfaOLMar8V34w=
2+
github.com/otiai10/copy v1.5.1/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
3+
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
4+
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
5+
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
6+
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
7+
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
88
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
99
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
1010
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
@@ -17,7 +17,3 @@ golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXR
1717
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
1818
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
1919
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
20-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
21-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
23-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL