Skip to content
This repository was archived by the owner on Oct 15, 2023. It is now read-only.

Commit 83d19bf

Browse files
authored
v0.6.2: LatestRelease <- Development (#82)
2 parents 93a9505 + 17b6bd6 commit 83d19bf

File tree

27 files changed

+786
-467
lines changed

27 files changed

+786
-467
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go Tests (Linux)
5+
6+
on:
7+
# push:
8+
# branches: [ "Development" ]
9+
pull_request:
10+
branches: [ "Development", "LatestRelease" ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
#- uses: browser-actions/setup-chrome@v1
19+
#- run: chrome --version
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v3
23+
with:
24+
go-version: 1.19
25+
26+
- name: Go Tests
27+
run: go test -v ./tests/...
28+
29+
# - name: Go Tests utils
30+
# run: go test -v ./tests/utils
31+
32+
#- name: Go Tests net
33+
# run: go test -v ./tests/utils/net

.github/workflows/Run-Go-Tests.yml renamed to .github/workflows/Run-Go-Tests-Windows.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This workflow will build a golang project
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
33

4-
name: Go Tests (only random package)
4+
name: Go Tests (Windows)
55

66
on:
77
# push:
88
# branches: [ "Development" ]
99
pull_request:
10-
branches: [ "Development" ]
10+
branches: [ "Development", "LatestRelease" ]
1111

1212
jobs:
1313
build:
@@ -23,8 +23,8 @@ jobs:
2323
with:
2424
go-version: 1.19
2525

26-
- name: Go Test random package
27-
run: go test -v ./tests/utils/random
26+
- name: Go Tests
27+
run: go test -v ./tests/...
2828

2929
# - name: Go Tests utils
3030
# run: go test -v ./tests/utils

README.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,60 @@ Example: how to add framework to main.go
4242
package main
4343

4444
import (
45-
"github.com/lmbek/gobek/fileserver"
45+
"fmt"
4646
"github.com/lmbek/gobek/launcher"
47-
"net/http"
4847
"os"
49-
"runtime"
5048
)
5149

5250
// For windows we need a organisation name and project name
5351
var organisationName = "NewOrganisationName" // put in organisation name
5452
var projectName = "NewProjectName" // put in project name
5553

56-
//Remember to create this folder manually if it doesnt exist, and put a index.html file into it
5754
var frontendPath = "./frontend" // this should be set to where frontend files is (frontend folder: html, css, javascript...)
5855

59-
// remember to change the ports to something unique
6056
var chromeLauncher = launcher.ChromeLauncher{
61-
Location: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
62-
LocationCMD: "C:\\\"Program Files\"\\Google\\Chrome\\Application\\chrome.exe",
63-
FrontendInstallLocation: os.Getenv("localappdata") + "\\Google\\Chrome\\InstalledApps\\" + organisationName + "\\" + projectName,
64-
Domain: "localhost",
65-
PortMin: 11430,
66-
PreferredPort: 11451,
67-
PortMax: 11500,
57+
Location: os.Getenv("programfiles") + "\\Google\\Chrome\\Application\\chrome.exe",
58+
FrontendInstallLocation: os.Getenv("localappdata") + "\\Google\\Chrome\\InstalledApps\\" + "DefaultOrganisationName" + "\\" + "DefaultProjectName",
6859
}
6960

7061
var chromiumLauncher = launcher.DefaultChromiumLauncher // default chrome or chromium launcher settings can be used like this
7162

72-
func main() {
73-
// if you want to have an api, you can add your own
74-
//http.HandleFunc("/api/", api.ServeAPIUseGZip)
63+
/*
64+
// Otherwise they can also be customized like this
65+
66+
var chromiumLauncher = launcher.ChromiumLauncher{
67+
Location: "/var/lib/snapd/desktop/applications/chromium_chromium.desktop", // TODO: check if better location or can be customised
68+
Domain: "localhost",
69+
}
70+
*/
7571

76-
// if you want to use your own http handlerFunc, you can use launcher.StartCustom instead
77-
err := launcher.Start(frontendPath, chromeLauncher, chromiumLauncher) // serves "/" as fileserver.ServeFileServer. If you want to manage "/", then use launcher.StartCustom() instead
72+
func main() {
73+
// add your own API
74+
//api.Init()
75+
/*
76+
var once sync.Once
77+
once.Do(func() {
78+
http.HandleFunc("/", fileserver.ServeFileServer)
79+
http.HandleFunc("/api/", api.ServeAPIUseGZip)
80+
})
81+
err := launcher.Start(frontendPath, chromeLauncher, chromiumLauncher) // serves "/" as fileserver.ServeFileServer. If you want to manage "/", then use launcher.StartCustom() instead
82+
if err != nil {
83+
fmt.Println(err)
84+
}
85+
*/
86+
err := launcher.StartDefault(frontendPath, chromeLauncher, chromiumLauncher)
7887
if err != nil {
7988
fmt.Println(err)
8089
}
8190
}
91+
8292
</pre>
8393

94+
## How to test
95+
<code>go test ./tests/...</code>
96+
8497
## How to run
85-
<code>go run main.go</code>
98+
make your own main.go by following https://github.com/lmbek/gobek-example
8699

87100
## How to apply manifest and logo to executible
88101
Use something like goversioninfo: https://github.com/josephspurrier/goversioninfo
@@ -94,4 +107,4 @@ Use something like goversioninfo: https://github.com/josephspurrier/goversioninf
94107
Coming later
95108

96109
## Further plans
97-
I want to embed chromium or webview into this project at some time. Please let me know or make a pull request if you want to help.
110+
Huge changes coming to version 0.7.0 that will change the whole project structure, this will break all versions before 0.7.0 when upgrading

fileserver/fileserver.go

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import (
1010
"net/http"
1111
"os"
1212
"os/signal"
13+
"path"
1314
"strings"
1415
"syscall"
1516
"time"
1617
)
1718

1819
var FrontendPath = "./frontend" // should be set doing runtime by main.go
1920
var Server = http.Server{
20-
Addr: "", // should be set doing runtime by main.go with fileserver.SetServerAddress
21+
Addr: "localhost:0", // port is set on runtime
2122
Handler: nil,
2223
TLSConfig: nil,
2324
ReadTimeout: 5 * time.Second,
@@ -61,26 +62,71 @@ func ServeFileServer(response http.ResponseWriter, request *http.Request) {
6162

6263
func setHeaders(response http.ResponseWriter, request *http.Request) http.ResponseWriter {
6364
// Headers can be set here
64-
// Add Cache Cache-Control: max-age=31536000, immutable
6565

66-
// response.Header().Add("Cache-Control", "max-age=31536000, immutable")
66+
// set content-type for requested url path
67+
contentType := getContentType(path.Ext(request.URL.Path))
68+
response.Header().Set("Content-Type", contentType)
6769

68-
// Check if the requested file has a ".css" extension
69-
if strings.HasSuffix(request.URL.Path, ".html") {
70-
response.Header().Set("Content-Type", "text/html")
71-
}
70+
response.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate")
71+
response.Header().Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT")
7272

73-
if strings.HasSuffix(request.URL.Path, ".js") {
74-
response.Header().Set("Content-Type", "application/javascript")
75-
}
73+
// Add Cache Cache-Control: max-age=31536000, immutable
74+
// response.Header().Add("Cache-Control", "max-age=31536000, immutable")
75+
return response
76+
}
7677

77-
if strings.HasSuffix(request.URL.Path, ".css") {
78-
response.Header().Set("Content-Type", "text/css")
78+
func getContentType(ext string) string {
79+
if len(ext) == 0 {
80+
return "text/html" // return and do not run further if no extension, we assume it is html
7981
}
8082

81-
response.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate")
82-
response.Header().Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT")
83-
return response
83+
switch ext {
84+
case ".html", ".htm", ".shtml":
85+
return "text/html"
86+
case ".css":
87+
return "text/css"
88+
case ".js":
89+
return "application/javascript"
90+
case ".json":
91+
return "application/json"
92+
case ".xml":
93+
return "application/xml"
94+
case ".pdf":
95+
return "application/pdf"
96+
case ".zip":
97+
return "application/zip"
98+
case ".gzip", ".gz":
99+
return "application/gzip"
100+
case ".png":
101+
return "image/png"
102+
case ".jpg", ".jpeg":
103+
return "image/jpeg"
104+
case ".gif":
105+
return "image/gif"
106+
case ".svg":
107+
return "image/svg+xml"
108+
case ".webp":
109+
return "image/webp"
110+
case ".ico":
111+
return "image/x-icon"
112+
case ".mp4":
113+
return "video/mp4"
114+
case ".webm":
115+
return "video/webm"
116+
case ".mp3":
117+
return "audio/mpeg"
118+
case ".wav":
119+
return "audio/wav"
120+
case ".ogg":
121+
return "audio/ogg"
122+
// cases like these below should be handled by an API, that should return something custom
123+
//case ".exe":
124+
// return "application/octet-stream"
125+
//case ".msi":
126+
// return "application/octet-stream"
127+
default:
128+
return "text/plain"
129+
}
84130
}
85131

86132
func Start() error {
@@ -91,18 +137,20 @@ func Start() error {
91137
return nil
92138
}
93139

140+
// TODO: Make proper tests for graceful shutdowns, maybe it does not work properly, remove this comment when confirmed
94141
func Shutdown(serverContext context.Context) error {
95142
serverContext, cancel := context.WithTimeout(serverContext, ServerGraceShutdownTime)
96143
defer cancel()
97144
err := Server.Shutdown(serverContext)
98145
if err != nil {
99-
log.Println("Failed to gracefully shutdown the server:", err)
146+
log.Println("Failed to gracefully shutdown the server: ", err)
100147
return err
101148
}
102149
log.Println("Server has been shut down gracefully")
103150
return nil
104151
}
105152

153+
// TODO: Make proper tests for graceful shutdowns, maybe it does not work properly, remove this comment when confirmed
106154
func GracefulStart() error {
107155
err := Start()
108156

@@ -113,7 +161,8 @@ func GracefulStart() error {
113161
} else {
114162
_, closeChannel := CreateChannel()
115163
defer closeChannel()
116-
log.Println("Application stopped gracefully")
164+
// Error shutting down gracefully
165+
fmt.Println("Application stopped gracefully")
117166
return Shutdown(context.Background())
118167
}
119168
}

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use .

0 commit comments

Comments
 (0)