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

Commit 8dfdaf8

Browse files
authored
v0.6.3: LatestRelease <- Development (#84)
2 parents 83d19bf + 7e3600d commit 8dfdaf8

File tree

5 files changed

+21
-118
lines changed

5 files changed

+21
-118
lines changed

README.md

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,36 @@ Example: how to add framework to main.go
4242
package main
4343

4444
import (
45+
"api"
4546
"fmt"
47+
"github.com/lmbek/gobek/fileserver"
4648
"github.com/lmbek/gobek/launcher"
4749
"os"
4850
)
4951

50-
// For windows we need a organisation name and project name
51-
var organisationName = "NewOrganisationName" // put in organisation name
52-
var projectName = "NewProjectName" // put in project name
52+
// For windows, we need an organisation name and project name
53+
var organisationName = "NewOrganisationName"
54+
var projectName = "NewProjectName"
5355

54-
var frontendPath = "./frontend" // this should be set to where frontend files is (frontend folder: html, css, javascript...)
56+
// Set frontend path (where we have all the: html, css, javascript...)
57+
var frontendPath = "./frontend"
5558

5659
var chromeLauncher = launcher.ChromeLauncher{
5760
Location: os.Getenv("programfiles") + "\\Google\\Chrome\\Application\\chrome.exe",
58-
FrontendInstallLocation: os.Getenv("localappdata") + "\\Google\\Chrome\\InstalledApps\\" + "DefaultOrganisationName" + "\\" + "DefaultProjectName",
61+
FrontendInstallLocation: os.Getenv("localappdata") + "\\Google\\Chrome\\InstalledApps\\" + organisationName + "\\" + projectName,
5962
}
6063

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

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-
*/
71-
7266
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-
*/
67+
//api.Init() // need to be added by you (example on gobek-example)
8668
err := launcher.StartDefault(frontendPath, chromeLauncher, chromiumLauncher)
8769
if err != nil {
8870
fmt.Println(err)
8971
}
9072
}
91-
9273
</pre>
93-
74+
Please do note however that using the main.go from the gobek-example project is recommended
9475
## How to test
9576
<code>go test ./tests/...</code>
9677

@@ -102,9 +83,3 @@ Use something like goversioninfo: https://github.com/josephspurrier/goversioninf
10283

10384
## How to build
10485
<code>go build -ldflags -H=windowsgui -o NewProjectName.exe</code>
105-
106-
## How to make setup file and update functionality
107-
Coming later
108-
109-
## Further plans
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: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ import (
1010
"net/http"
1111
"os"
1212
"os/signal"
13-
"path"
1413
"strings"
1514
"syscall"
1615
"time"
1716
)
1817

1918
var FrontendPath = "./frontend" // should be set doing runtime by main.go
19+
20+
// We want our server to serve requests without timeout, as we might want to make use of native features with some of them blocking
2021
var Server = http.Server{
2122
Addr: "localhost:0", // port is set on runtime
2223
Handler: nil,
2324
TLSConfig: nil,
24-
ReadTimeout: 5 * time.Second,
25-
ReadHeaderTimeout: 20 * time.Second,
26-
WriteTimeout: 10 * time.Second,
25+
ReadTimeout: 0,
26+
ReadHeaderTimeout: 0,
27+
WriteTimeout: 0,
2728
IdleTimeout: 0,
2829
MaxHeaderBytes: 0,
2930
TLSNextProto: nil,
@@ -35,7 +36,7 @@ var Server = http.Server{
3536
var ServerGraceShutdownTime = 5 * time.Second
3637

3738
func SetServerAddress(address string) {
38-
fmt.Println("address set to: " + address)
39+
fmt.Println("Address set to: " + address)
3940
Server.Addr = address
4041
}
4142

@@ -63,72 +64,15 @@ func ServeFileServer(response http.ResponseWriter, request *http.Request) {
6364
func setHeaders(response http.ResponseWriter, request *http.Request) http.ResponseWriter {
6465
// Headers can be set here
6566

66-
// set content-type for requested url path
67-
contentType := getContentType(path.Ext(request.URL.Path))
68-
response.Header().Set("Content-Type", contentType)
69-
67+
// We are using no caching because this is a local application, we could probably speed up application by making cache
7068
response.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate")
71-
response.Header().Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT")
72-
69+
// response.Header().Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT")
70+
// response.Header().Set("Cache-Control", "must-revalidate, max-age=31536000")
7371
// Add Cache Cache-Control: max-age=31536000, immutable
7472
// response.Header().Add("Cache-Control", "max-age=31536000, immutable")
7573
return response
7674
}
7775

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
81-
}
82-
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-
}
130-
}
131-
13276
func Start() error {
13377
err := Server.ListenAndServe()
13478
if err != nil {

go.work

Lines changed: 0 additions & 1 deletion
This file was deleted.

launcher/chromeLauncher.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ func (launcher *ChromeLauncher) launchForWindows() bool {
4949
fileserver.SetServerAddress("localhost:" + port)
5050

5151
// Print the port that was found
52-
fmt.Println("selected address with port: http://" + fileserver.GetServerAddress())
52+
fmt.Println("Selected address with port: http://" + fileserver.GetServerAddress())
5353

5454
// Start frontend by starting a new Chrome process
5555
path := launcher.Location
5656

5757
cmd = exec.Command(path, "--app=http://"+fileserver.GetServerAddress(), "--user-data-dir="+launcher.FrontendInstallLocation)
5858
err = cmd.Start()
5959
if err != nil {
60-
println("Warning: Chrome could not start, is it installed?")
60+
println("warning: Chrome could not start, is it installed?")
6161
}
6262

6363
// Set up a signal handler to shutdown the program, when it should shutdown
@@ -107,19 +107,6 @@ func (launcher *ChromeLauncher) launchForWindows() bool {
107107
return false
108108
}
109109

110-
/*
111-
func (launcher *ChromeLauncher) assertChromeIsInstalled() {
112-
// check if chrome.exe is installed
113-
_, err := os.Stat(launcher.Location)
114-
115-
// if not installed give warning
116-
if err != nil {
117-
//messageboxw.WarningYouNeedToInstallChrome()
118-
os.Exit(0)
119-
}
120-
}
121-
*/
122-
123110
func (launcher *ChromeLauncher) isApplicationInstalled() bool {
124111
// check if this application is installed
125112
_, err := os.Stat(launcher.FrontendInstallLocation)

tests/launcher/launcher_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"time"
1212
)
1313

14-
// TODO: in version 0.7.0 this should be splitted into each of the chrome/chromium launchers instead
15-
1614
// SIMPLE VERSION
1715
func TestStart(test *testing.T) {
1816
//tests.PrintGotFatalError(test, "NOT IMPLEMENTED YET!")

0 commit comments

Comments
 (0)