Refactoring to comply with standard go package structure
@@ -10,7 +10,7 @@ RUN cd /compile && go mod download
|
||||
|
||||
COPY . /compile
|
||||
|
||||
RUN cd /compile && go generate && CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/src/environment.IsDocker=true' -X 'Gokapi/src/environment.Builder=Project Docker File' -X 'Gokapi/src/environment.BuildTime=$(date)'" -o /compile/gokapi
|
||||
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
|
||||
|
||||
FROM alpine:3.13
|
||||
|
||||
|
||||
16
Main.go
@@ -5,10 +5,10 @@ Main routine
|
||||
*/
|
||||
|
||||
import (
|
||||
"Gokapi/src/configuration"
|
||||
"Gokapi/src/environment"
|
||||
"Gokapi/src/storage"
|
||||
"Gokapi/src/webserver"
|
||||
"Gokapi/internal/configuration"
|
||||
"Gokapi/internal/environment"
|
||||
"Gokapi/internal/storage"
|
||||
"Gokapi/internal/webserver"
|
||||
"embed"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
|
||||
// Current version in readable form. The go generate call below
|
||||
// needs to be modified as well
|
||||
const VERSION = "1.1.3"
|
||||
const VERSION = "1.1.4-dev"
|
||||
|
||||
//go:generate sh "./.release/setVersionTemplate.sh" "1.1.3"
|
||||
//go:generate sh "./build/setVersionTemplate.sh" "1.1.4-dev"
|
||||
|
||||
// Main routine that is called on startup
|
||||
func main() {
|
||||
@@ -61,12 +61,12 @@ func checkArguments() {
|
||||
|
||||
// Embedded version of the "static" folder
|
||||
// This contains JS files, CSS, images etc
|
||||
//go:embed static
|
||||
//go:embed web/static
|
||||
var staticFolderEmbedded embed.FS
|
||||
|
||||
// Embedded version of the "templates" folder
|
||||
// This contains templates that Gokapi uses for creating the HTML output
|
||||
//go:embed templates
|
||||
//go:embed web/templates
|
||||
var templateFolderEmbedded embed.FS
|
||||
|
||||
// ASCII art logo
|
||||
|
||||
@@ -90,7 +90,7 @@ For Linux environments, execute the binary in this format: `GOKAPI_USERNAME=admi
|
||||
|
||||
By default, all files are included in the executable. If you want to change the layout (e.g. add your company logo or change the app name etc.), follow these steps:
|
||||
* Clone this repository
|
||||
* Copy either the folder `static`, `templates` or both to the directory where the executable is located
|
||||
* Copy either the folder `static`, `templates` or both from the `web` folder to the directory where the executable is located
|
||||
* Make changes to the folders. `static` contains images, CSS files and JavaScript. `templates` contains the HTML code.
|
||||
* Restart the server. If the folders exist, the server will use the local files instead of the embedded files
|
||||
* Optional: To embed the files permanently, the executable needs to be recompiled with `go build`.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FROM golang:1.16
|
||||
|
||||
## To compile:
|
||||
## cd Gokapi/release/
|
||||
## cd Gokapi/build/
|
||||
## docker build . --tag gokapi-builder
|
||||
## docker run --rm -it -v ../:/usr/src/myapp -w /usr/src/myapp gokapi-builder
|
||||
|
||||
@@ -17,11 +17,11 @@ for target in $targets; do
|
||||
fi
|
||||
|
||||
echo "----> Building project for: $target"
|
||||
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/src/environment.Builder=Github Release Builder' -X 'Gokapi/src/environment.BuildTime=$(date)'" -o $output
|
||||
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
|
||||
zip -j $output.zip $output > /dev/null
|
||||
rm $output
|
||||
done
|
||||
|
||||
echo "----> Build is complete. List of files at $release_path:"
|
||||
cd .release/
|
||||
cd build/
|
||||
ls -l gokapi-*
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#Called by go generate
|
||||
#Sets the version number in the template automatically
|
||||
sed -i 's/{{define "version"}}.*{{end}}/{{define "version"}}'$1'{{end}}/g' ./templates/string_constants.tmpl
|
||||
sed -i 's/{{define "version"}}.*{{end}}/{{define "version"}}'$1'{{end}}/g' ./web/templates/string_constants.tmpl
|
||||
@@ -5,10 +5,10 @@ Loading and saving of the persistent configuration
|
||||
*/
|
||||
|
||||
import (
|
||||
"Gokapi/src/environment"
|
||||
"Gokapi/src/helper"
|
||||
"Gokapi/src/storage/filestructure"
|
||||
"Gokapi/src/webserver/sessionstructure"
|
||||
"Gokapi/internal/environment"
|
||||
"Gokapi/internal/helper"
|
||||
"Gokapi/internal/storage/filestructure"
|
||||
"Gokapi/internal/webserver/sessionstructure"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -5,9 +5,9 @@ Serving and processing uploaded files
|
||||
*/
|
||||
|
||||
import (
|
||||
"Gokapi/src/configuration"
|
||||
"Gokapi/src/helper"
|
||||
"Gokapi/src/storage/filestructure"
|
||||
"Gokapi/internal/configuration"
|
||||
"Gokapi/internal/helper"
|
||||
"Gokapi/internal/storage/filestructure"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
@@ -5,9 +5,9 @@ Manages the sessions for the admin user or to access password protected files
|
||||
*/
|
||||
|
||||
import (
|
||||
"Gokapi/src/configuration"
|
||||
"Gokapi/src/helper"
|
||||
"Gokapi/src/webserver/sessionstructure"
|
||||
"Gokapi/internal/configuration"
|
||||
"Gokapi/internal/helper"
|
||||
"Gokapi/internal/webserver/sessionstructure"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -5,10 +5,10 @@ Handling of webserver and requests / uploads
|
||||
*/
|
||||
|
||||
import (
|
||||
"Gokapi/src/configuration"
|
||||
"Gokapi/src/helper"
|
||||
"Gokapi/src/storage"
|
||||
"Gokapi/src/storage/filestructure"
|
||||
"Gokapi/internal/configuration"
|
||||
"Gokapi/internal/helper"
|
||||
"Gokapi/internal/storage"
|
||||
"Gokapi/internal/storage/filestructure"
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -34,7 +34,7 @@ const expiredFile = "static/expired.png"
|
||||
// Starts the webserver on the port set in the config
|
||||
func Start(staticFolderEmbedded, templateFolderEmbedded *embed.FS) {
|
||||
initTemplates(*templateFolderEmbedded)
|
||||
webserverDir, _ := fs.Sub(*staticFolderEmbedded, "static")
|
||||
webserverDir, _ := fs.Sub(*staticFolderEmbedded, "web/static")
|
||||
var err error
|
||||
if helper.FolderExists("static") {
|
||||
fmt.Println("Found folder 'static', using local folder instead of internal static folder")
|
||||
@@ -43,7 +43,7 @@ func Start(staticFolderEmbedded, templateFolderEmbedded *embed.FS) {
|
||||
helper.Check(err)
|
||||
} else {
|
||||
http.Handle("/", http.FileServer(http.FS(webserverDir)))
|
||||
imageExpiredPicture, err = fs.ReadFile(staticFolderEmbedded, expiredFile)
|
||||
imageExpiredPicture, err = fs.ReadFile(staticFolderEmbedded, "web/"+expiredFile)
|
||||
helper.Check(err)
|
||||
}
|
||||
http.HandleFunc("/index", showIndex)
|
||||
@@ -77,7 +77,7 @@ func initTemplates(templateFolderEmbedded embed.FS) {
|
||||
templateFolder, err = template.ParseGlob("templates/*.tmpl")
|
||||
helper.Check(err)
|
||||
} else {
|
||||
templateFolder, err = template.ParseFS(templateFolderEmbedded, "templates/*.tmpl")
|
||||
templateFolder, err = template.ParseFS(templateFolderEmbedded, "web/templates/*.tmpl")
|
||||
helper.Check(err)
|
||||
}
|
||||
}
|
||||
@@ -259,6 +259,8 @@ type UploadView struct {
|
||||
DefaultExpiry int
|
||||
DefaultPassword string
|
||||
IsAdminView bool
|
||||
IsMainView bool
|
||||
IsApiView bool
|
||||
}
|
||||
|
||||
// Converts the globalConfig variable to an UploadView struct to pass the infos to
|
||||
@@ -283,6 +285,7 @@ func (u *UploadView) convertGlobalConfig() *UploadView {
|
||||
u.DefaultDownloads = configuration.ServerSettings.DefaultDownloads
|
||||
u.TimeNow = time.Now().Unix()
|
||||
u.IsAdminView = true
|
||||
u.IsMainView = true
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
{{define "app_name"}}Gokapi{{end}}
|
||||
{{define "version"}}1.1.3{{end}}
|
||||
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 369 B After Width: | Height: | Size: 369 B |
|
Before Width: | Height: | Size: 724 B After Width: | Height: | Size: 724 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -43,7 +43,7 @@
|
||||
<div style="max-width: 80em; margin: 0 auto;" class="inner">
|
||||
<h1>{{template "app_name"}}</h1>
|
||||
<nav class="nav nav-masthead justify-content-center">
|
||||
<a class="nav-link active" href="#">Upload</a>
|
||||
<a class="nav-link {{ if .IsMainView }}active{{ end }}" href="#">Upload</a>
|
||||
<a class="nav-link" href="./logout">Logout</a>
|
||||
</nav>
|
||||
</div>
|
||||
2
web/templates/string_constants.tmpl
Normal file
@@ -0,0 +1,2 @@
|
||||
{{define "app_name"}}Gokapi{{end}}
|
||||
{{define "version"}}1.1.4-dev{{end}}
|
||||