-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
69 lines (58 loc) · 1.97 KB
/
app.go
File metadata and controls
69 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"controllers"
"errors"
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/wswag/webview"
)
var mainViewController *controllers.MainViewController
// ConfigureWindow should return an initialized window.Settings object to initialize
// the webview window
func ConfigureWindow() webview.Settings {
return webview.Settings{
Width: 800,
Height: 600,
Resizable: true,
Title: "Hello WebView!",
Debug: true,
}
}
// SetupServer should initialize server routes etc.
// note that there will also be a route to a http.FileServer be added
// to '/' to provide asset content
// an example usage is adding an api route to provide local hdd file content
// As the view has not yet been initialized, you may not call any
// code injection funcs here
func SetupServer(router *mux.Router) {
mainViewController = &controllers.MainViewController{
Title: "Hello Go Controller!",
Answer: 42,
}
// add some custom routes providing queryable data beside js bindings
router.PathPrefix("/local/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(404) })
// do some stuff maybe
fmt.Println("Server controllers initialized")
}
// SetupView might inject additional code on startup and/or setup the controllers.
// Note that code injection is performed after the page has already been loaded
func SetupView() {
}
// QueryService should return a service interface identified by the given name which
// then will be injected into javascript and be available as a js object through this name.
// Note that all properties of this struct will be accessible under name.data in js!
// an injection is queried from HTML content by adding a <script> tag pointing to
// the inject API route, eg:
//
// <script src="/inject/model.js"></script>
//
func QueryService(name string) (interface{}, error) {
// map your services here
switch name {
case "model":
return mainViewController, nil
default:
return nil, errors.New("Service not available")
}
}