/ main.go
main.go
  1  package main
  2  
  3  import (
  4  	"log"
  5  	"net/http"
  6  
  7  	"github.com/maxence-charriere/go-app/v10/pkg/app"
  8  )
  9  
 10  type Descriptor struct {
 11  	X      int `json:"x"`
 12  	Y      int `json:"y"`
 13  	Width  int `json:"width"`
 14  	Height int `json:"height"`
 15  }
 16  
 17  type RequestBody struct {
 18  	Descriptor []Descriptor `json:"descriptor"`
 19  }
 20  
 21  // The main function is the entry point where the app is configured and started.
 22  // It is executed in 2 different environments: A client (the web browser) and a
 23  // server.
 24  func main() {
 25  	// The first thing to do is to associate the wallet component with a path.
 26  	//
 27  	// This is done by calling the Route() function,  which tells go-app what
 28  	// component to display for a given path, on both client and server-side.
 29  	app.Route("/", func() app.Composer { return &home{} })
 30  	app.Route("/auth", func() app.Composer { return &auth{} })
 31  	app.Route("/wallet", func() app.Composer { return &wallet{} })
 32  	app.Route("/wallets", func() app.Composer { return &wallets{} })
 33  	app.Route("/transactions", func() app.Composer { return &transactions{} })
 34  	app.RouteWithRegexp("/transactions/(?P<uuid>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})", func() app.Composer { return &transactions{} })
 35  	app.RouteWithRegexp("/tax/(?P<uuid>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})", func() app.Composer { return &tax{} })
 36  	app.Route("/payment", func() app.Composer { return &payment{} })
 37  	app.Route("/subscriptions", func() app.Composer { return &subscription{} })
 38  	// business only
 39  	app.Route("/plan", func() app.Composer { return &plan{} })
 40  	app.Route("/associates", func() app.Composer { return &associate{} })
 41  	app.Route("/clients", func() app.Composer { return &client{} })
 42  	app.Route("/suppliers", func() app.Composer { return &supplier{} })
 43  	app.Route("/terms", func() app.Composer { return &terms{} })
 44  	app.Route("/terms-business", func() app.Composer { return &termsBusiness{} })
 45  	app.Route("/terms-government", func() app.Composer { return &termsGovernment{} })
 46  	app.Route("/privacy", func() app.Composer { return &privacy{} })
 47  	app.Route("/cookie", func() app.Composer { return &cookie{} })
 48  
 49  	// Once the routes set up, the next thing to do is to either launch the app
 50  	// or the server that serves the app.
 51  	//
 52  	// When executed on the client-side, the RunWhenOnBrowser() function
 53  	// launches the app,  starting a loop that listens for app events and
 54  	// executes client instructions. Since it is a blocking call, the code below
 55  	// it will never be executed.
 56  	//
 57  	// When executed on the server-side, RunWhenOnBrowser() does nothing, which
 58  	// lets room for server implementation without the need for precompiling
 59  	// instructions.
 60  	app.RunWhenOnBrowser()
 61  
 62  	// Finally, launching the server that serves the app is done by using the Go
 63  	// standard HTTP package.
 64  	//
 65  	// The Handler is an HTTP handler that serves the client and all its
 66  	// required resources to make it work into a web browser. Here it is
 67  	// configured to handle requests with a path that starts with "/".
 68  	http.Handle("/", &app.Handler{
 69  		Name:        "Cyber GUBI",
 70  		Description: "An unconditional universal basic income",
 71  		Styles: []string{
 72  			"/web/app.css", // Loads app.css file.
 73  		},
 74  		Scripts: []string{
 75  			"web/script.js",
 76  			"web/helpers.js",
 77  		},
 78  		RawHeaders: []string{
 79  			`
 80  			<script src="https://cdn.jsdelivr.net/npm/@vladmandic/face-api/dist/face-api.js"></script>`,
 81  		},
 82  	})
 83  
 84  	http.Handle("/auth", &app.Handler{
 85  		Name:        "Cyber GUBI",
 86  		Description: "An unconditional universal basic income",
 87  		Styles: []string{
 88  			"/web/app.css", // Loads app.css file.
 89  		},
 90  		Scripts: []string{
 91  			"web/script.js",
 92  			"web/helpers.js",
 93  		},
 94  		RawHeaders: []string{
 95  			`
 96  			<script src="https://cdn.jsdelivr.net/npm/@vladmandic/face-api/dist/face-api.js"></script>`,
 97  		},
 98  	})
 99  
100  	http.Handle("/wallet", &app.Handler{
101  		Name:        "Cyber GUBI",
102  		Description: "An unconditional universal basic income",
103  		Styles: []string{
104  			"/web/app.css", // Loads app.css file.
105  		},
106  	})
107  
108  	http.Handle("/wallets", &app.Handler{
109  		Name:        "Cyber GUBI",
110  		Description: "An unconditional universal basic income",
111  		Styles: []string{
112  			"/web/app.css", // Loads app.css file.
113  		},
114  		Scripts: []string{
115  			"web/helpers.js",
116  		},
117  	})
118  
119  	http.Handle("/transactions", &app.Handler{
120  		Name:        "Cyber GUBI",
121  		Description: "An unconditional universal basic income",
122  		Styles: []string{
123  			"/web/app.css", // Loads app.css file.
124  		},
125  		Scripts: []string{
126  			"web/helpers.js",
127  		},
128  	})
129  
130  	http.Handle("/tax", &app.Handler{
131  		Name:        "Cyber GUBI",
132  		Description: "An unconditional universal basic income",
133  		Styles: []string{
134  			"/web/app.css", // Loads app.css file.
135  		},
136  	})
137  
138  	http.Handle("/payment", &app.Handler{
139  		Name:        "Cyber GUBI",
140  		Description: "An unconditional universal basic income",
141  		Styles: []string{
142  			"/web/app.css", // Loads app.css file.
143  		},
144  	})
145  
146  	http.Handle("/subscriptions", &app.Handler{
147  		Name:        "Cyber GUBI",
148  		Description: "An unconditional universal basic income",
149  		Styles: []string{
150  			"/web/app.css", // Loads app.css file.
151  		},
152  	})
153  
154  	http.Handle("/plan", &app.Handler{
155  		Name:        "Cyber GUBI",
156  		Description: "An unconditional universal basic income",
157  		Styles: []string{
158  			"/web/app.css", // Loads app.css file.
159  		},
160  	})
161  
162  	http.Handle("/associates", &app.Handler{
163  		Name:        "Cyber GUBI",
164  		Description: "An unconditional universal basic income",
165  		Styles: []string{
166  			"/web/app.css", // Loads app.css file.
167  		},
168  	})
169  
170  	http.Handle("/clients", &app.Handler{
171  		Name:        "Cyber GUBI",
172  		Description: "An unconditional universal basic income",
173  		Styles: []string{
174  			"/web/app.css", // Loads app.css file.
175  		},
176  	})
177  
178  	http.Handle("/suppliers", &app.Handler{
179  		Name:        "Cyber GUBI",
180  		Description: "An unconditional universal basic income",
181  		Styles: []string{
182  			"/web/app.css", // Loads app.css file.
183  		},
184  	})
185  
186  	http.Handle("/terms", &app.Handler{
187  		Name:        "Cyber GUBI",
188  		Description: "An unconditional universal basic income",
189  		Styles: []string{
190  			"/web/app.css", // Loads app.css file.
191  		},
192  	})
193  
194  	http.Handle("/terms-business", &app.Handler{
195  		Name:        "Cyber GUBI",
196  		Description: "An unconditional universal basic income",
197  		Styles: []string{
198  			"/web/app.css", // Loads app.css file.
199  		},
200  	})
201  
202  	http.Handle("/terms-government", &app.Handler{
203  		Name:        "Cyber GUBI",
204  		Description: "An unconditional universal basic income",
205  		Styles: []string{
206  			"/web/app.css", // Loads app.css file.
207  		},
208  	})
209  
210  	http.Handle("/privacy", &app.Handler{
211  		Name:        "Cyber GUBI",
212  		Description: "An unconditional universal basic income",
213  		Styles: []string{
214  			"/web/app.css", // Loads app.css file.
215  		},
216  	})
217  
218  	http.Handle("/cookie", &app.Handler{
219  		Name:        "Cyber GUBI",
220  		Description: "An unconditional universal basic income",
221  		Styles: []string{
222  			"/web/app.css", // Loads app.css file.
223  		},
224  	})
225  
226  	if err := http.ListenAndServe(":8000", nil); err != nil {
227  		log.Fatal(err)
228  	}
229  }