diff --git a/.gitignore b/.gitignore index fb22b8b..76a9167 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ example/generate *.android *.linux example/resource.syso +go.work.sum \ No newline at end of file diff --git a/README.md b/README.md index fc1652f..8ceb592 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,120 @@ # go-local-web-example +(This readme is a duplicate of go-local-web-gui) + go-local-web (GOLW) is a simple framework made for developing localhosted software that can reuse chrome/chromium or embed chromium (in future releases). Both available in deployment for the applications. + +This framework uses Chrome (Windows) or Chromium (Linux) as frontend by opening them with cmd/terminal and hosting a localhost webserver, while opening chrome/chromium with --app and --user-directory arguments. The frontend can be changed by the user in runtime, while the backend needs to be compiled/build. The API can be decoupled in future versions, so every part of the application is changeable - Sustainable development. Frontends is easy to change. Alternatives to this is embedding a chromium or webview framework into the project, which will require more space. I chose to depend on Chrome/Chromium, as they are market leaders and html/css/javascript technology frontrunners. + +Feel free to use this piece of software, I will be happy to assist you + +I am currently working on this project, it will be updated and maintained. I consider it production ready. + +This project is used by Beksoft ApS for projects such as: +* BekCMS +* (name not announced yet) Password Manager +* PingPong Game made in Three.js +* Several local webbased software projects + +Write to me at lars@beksoft.dk if you want to have your project listed + +## Requirements to developers +Go 1.19+ +Chrome (Windows) or Chromium (Linux) + +## Requirements for users +Chrome (Windows) or Chromium (Linux) + +## How to use (download example project) +The best way to start using the project is to download the example project at: +https://github.com/NineNineFive/go-local-web-example + +This example project uses this package and combines it with a local api +Then the Go api is being developed and customized by you together with the frontend (JavaScript, HTML, CSS) + +## How to use (with go get) +first run the following in CMD (with go installed) +go get github.com/NineNineFive/go-local-web-gui +Example: how to add framework to main.go +
+package main
+
+import (
+	"github.com/NineNineFive/go-local-web-gui/fileserver"
+	"github.com/NineNineFive/go-local-web-gui/launcher"
+	"net/http"
+	"os"
+	"runtime"
+)
+
+// For windows we need a organisation name and project name
+var organisationName = "NewOrganisationName" // put in organisation name
+var projectName = "NewProjectName"           // put in project name
+
+var frontendPath = "./frontend" // this should be set to where frontend files is (frontend folder: html, css, javascript...)
+
+// remember to change the ports to something unique
+var chromeLauncher = launcher.ChromeLauncher{
+	Location:                "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
+	LocationCMD:             "C:\\\"Program Files\"\\Google\\Chrome\\Application\\chrome.exe",
+	FrontendInstallLocation: os.Getenv("localappdata") + "\\Google\\Chrome\\InstalledApps\\" + organisationName + "\\" + projectName,
+	Domain:                  "localhost",
+	PortMin:                 11430,
+	PreferredPort:           11451,
+	PortMax:                 11500,
+}
+
+var chromiumLauncher = launcher.DefaultChromiumLauncher // default chrome or chromium launcher settings can be used like this
+/* // Otherwise they can also be customized like this
+var chromiumLauncher = launcher.ChromiumLauncher{
+	Location:      "/var/lib/snapd/desktop/applications/chromium_chromium.desktop", // TODO: check if better location or can be customised
+	Domain:        "localhost",
+	PortMin:       11430,
+	PreferredPort: 11451,
+	PortMax:       11500,
+}
+*/
+
+func main() {
+	launchApp()
+}
+
+func initHTTPHandlers() {
+    // static fileserver
+	http.HandleFunc("/", fileserver.ServeFileServer)
+
+    // api (local api can be added)
+	//http.HandleFunc("/api/", api.ServeAPIUseGZip)
+}
+
+func launchApp() {
+	switch runtime.GOOS {
+	case "windows":
+		initHTTPHandlers()
+		launcher.StartFrontendAndBackendWindows(frontendPath, chromeLauncher)
+		return
+	case "darwin": // "mac"
+		panic("Darwin Not Supported Yet")
+		return
+	case "linux": // "linux"
+		initHTTPHandlers()
+		launcher.StartFrontendAndBackendLinux(frontendPath, chromiumLauncher)
+		return
+	default: // "freebsd", "openbsd", "netbsd"
+		initHTTPHandlers()
+		launcher.StartFrontendAndBackendLinux(frontendPath, chromiumLauncher)
+		return
+	}
+}
+
+ +## How to run +go run main.go + +## How to apply manifest and logo to executible +Use something like goversioninfo: https://github.com/josephspurrier/goversioninfo + +## How to build +go build -ldflags -H=windowsgui -o NewProjectName.exe + +## How to make setup file and update functionality +Coming later \ No newline at end of file diff --git a/backend/go-local-web-api/api.go b/backend/api/api.go similarity index 100% rename from backend/go-local-web-api/api.go rename to backend/api/api.go diff --git a/backend/go-local-web-api/example/go.mod b/backend/api/example/go.mod similarity index 100% rename from backend/go-local-web-api/example/go.mod rename to backend/api/example/go.mod diff --git a/backend/go-local-web-api/example/list.go b/backend/api/example/list.go similarity index 100% rename from backend/go-local-web-api/example/list.go rename to backend/api/example/list.go diff --git a/backend/api/go.mod b/backend/api/go.mod new file mode 100644 index 0000000..186ac89 --- /dev/null +++ b/backend/api/go.mod @@ -0,0 +1,2 @@ +module api +go 1.19 // go version should be minimum 1.18 \ No newline at end of file diff --git a/backend/go-local-web-api/responseTypes.go b/backend/api/responseTypes.go similarity index 100% rename from backend/go-local-web-api/responseTypes.go rename to backend/api/responseTypes.go diff --git a/backend/go-local-web-api/LICENSE b/backend/go-local-web-api/LICENSE deleted file mode 100644 index 8e9a05c..0000000 --- a/backend/go-local-web-api/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Lars M Bek - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/backend/go-local-web-api/README.md b/backend/go-local-web-api/README.md deleted file mode 100644 index 616134f..0000000 --- a/backend/go-local-web-api/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# go-local-web-api -go-local-web (GOLW) is a simple framework made for developing localhosted software that can reuse chrome/chromium or embed chromium (in future releases). Both available in deployment for the applications. This repository is the api that can be used for go-local-web-gui diff --git a/backend/go-local-web-api/go.mod b/backend/go-local-web-api/go.mod deleted file mode 100644 index 824d30e..0000000 --- a/backend/go-local-web-api/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module api - -go 1.19 diff --git a/go.mod b/go.mod index a20d740..d1ce62b 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ -module go-local-web-gui +module GoLWExample go 1.19 -require github.com/NineNineFive/go-local-web-gui v0.4.3 // indirect +require github.com/NineNineFive/go-local-web-gui v0.4.9 // indirect \ No newline at end of file diff --git a/go.work b/go.work index f55d5fc..d6c104f 100644 --- a/go.work +++ b/go.work @@ -1,3 +1,3 @@ use . -use ./backend/go-local-web-api/ -use ./backend/go-local-web-api/example \ No newline at end of file +use ./backend/api +use ./backend/api/example \ No newline at end of file diff --git a/main.go b/main.go index bac5901..bd30a1e 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ // ** Reason Of Framework Explained ** // This application is meant to find a port and launch a frontend in chrome (windows) or chromium (linux). // Meanwhile, it will open a http localhost backend with an api. -// The API package at /development/backend/api/ can be replaced to fit another application, +// The API package at ./backend/api/ can be replaced to fit another application, // if the framework is to be used for other applications. // It is important to note, that the system will require a frontend directory and a data directory, // when the application is tested and released, these will also need to be managed (other applications can be put in) @@ -30,36 +30,42 @@ import ( "runtime" ) -var projectName = "NewProjectName" -var organisationName = "NewCompanyName" +// For windows we need a organisation name and project name +var organisationName = "NewOrganisationName" // put in organisation name +var projectName = "NewProjectName" // put in project name -// var address = "localhost:10995" -var frontendPath = "./frontend" +var frontendPath = "./frontend" // this should be set to where frontend files is (frontend folder: html, css, javascript...) var chromeLauncher = launcher.ChromeLauncher{ Location: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", LocationCMD: "C:\\\"Program Files\"\\Google\\Chrome\\Application\\chrome.exe", FrontendInstallLocation: os.Getenv("localappdata") + "\\Google\\Chrome\\InstalledApps\\" + organisationName + "\\" + projectName, Domain: "localhost", - PortMin: 19430, - PreferredPort: 19451, - PortMax: 19500, + PortMin: 11430, + PreferredPort: 11451, + PortMax: 11500, } +var chromiumLauncher = launcher.DefaultChromiumLauncher // default chrome or chromium launcher settings can be used like this +/* // Otherwise they can also be customized like this var chromiumLauncher = launcher.ChromiumLauncher{ Location: "/var/lib/snapd/desktop/applications/chromium_chromium.desktop", // TODO: check if better location or can be customised Domain: "localhost", - PortMin: 19430, - PreferredPort: 19451, - PortMax: 19500, + PortMin: 11430, + PreferredPort: 11451, + PortMax: 11500, } +*/ func main() { launchApp() } func initHTTPHandlers() { + // static fileserver http.HandleFunc("/", fileserver.ServeFileServer) + + // api (local api is at ./backend/api) http.HandleFunc("/api/", api.ServeAPIUseGZip) } @@ -67,18 +73,18 @@ func launchApp() { switch runtime.GOOS { case "windows": initHTTPHandlers() - launcher.StartFrontendAndBackendWindows(frontendPath, chromeLauncher) + launcher.StartOnWindows(frontendPath, chromeLauncher) return case "darwin": // "mac" panic("Darwin Not Supported Yet") return case "linux": // "linux" initHTTPHandlers() - launcher.StartFrontendAndBackendLinux(frontendPath, chromiumLauncher) + launcher.StartOnLinux(frontendPath, chromiumLauncher) return default: // "freebsd", "openbsd", "netbsd" initHTTPHandlers() - launcher.StartFrontendAndBackendLinux(frontendPath, chromiumLauncher) + launcher.StartOnLinux(frontendPath, chromiumLauncher) return } }