Hello world from go-app
This commit is contained in:
		
							parent
							
								
									cc94d487e1
								
							
						
					
					
						commit
						62383d28f9
					
				
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1 +1,3 @@
 | 
			
		||||
.vscode
 | 
			
		||||
.vscode
 | 
			
		||||
app
 | 
			
		||||
web/
 | 
			
		||||
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
build:
 | 
			
		||||
	GOARCH=wasm GOOS=js go build -o web/app.wasm
 | 
			
		||||
	go build -o app
 | 
			
		||||
 | 
			
		||||
run: build
 | 
			
		||||
	./app
 | 
			
		||||
							
								
								
									
										5
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								go.mod
									
									
									
									
									
								
							@ -1,3 +1,8 @@
 | 
			
		||||
module git.home.dutchellie.nl/DutchEllie/proper-website-2
 | 
			
		||||
 | 
			
		||||
go 1.17
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/google/uuid v1.3.0 // indirect
 | 
			
		||||
	github.com/maxence-charriere/go-app/v9 v9.3.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										19
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								go.sum
									
									
									
									
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
			
		||||
github.com/gomarkdown/markdown v0.0.0-20210408062403-ad838ccf8cdd/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
 | 
			
		||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
			
		||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
 | 
			
		||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
			
		||||
github.com/maxence-charriere/go-app/v9 v9.3.0 h1:PWNZWcme5hnMR9/cSdSRv+9WvPowETj0qhfy+3HCQRM=
 | 
			
		||||
github.com/maxence-charriere/go-app/v9 v9.3.0/go.mod h1:zo0n1kh4OMKn7P+MrTUUi7QwUMU2HOfHsZ293TITtxI=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
			
		||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
			
		||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
			
		||||
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
 | 
			
		||||
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
 | 
			
		||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 | 
			
		||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
			
		||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
							
								
								
									
										60
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/maxence-charriere/go-app/v9/pkg/app"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// hello is a component that displays a simple "Hello World!". A component is a
 | 
			
		||||
// customizable, independent, and reusable UI element. It is created by
 | 
			
		||||
// embedding app.Compo into a struct.
 | 
			
		||||
type hello struct {
 | 
			
		||||
	app.Compo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// The Render method is where the component appearance is defined. Here, a
 | 
			
		||||
// "Hello World!" is displayed as a heading.
 | 
			
		||||
func (h *hello) Render() app.UI {
 | 
			
		||||
	return app.H1().Text("Hello World!")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// The main function is the entry point where the app is configured and started.
 | 
			
		||||
// It is executed in 2 different environments: A client (the web browser) and a
 | 
			
		||||
// server.
 | 
			
		||||
func main() {
 | 
			
		||||
	// The first thing to do is to associate the hello component with a path.
 | 
			
		||||
	//
 | 
			
		||||
	// This is done by calling the Route() function,  which tells go-app what
 | 
			
		||||
	// component to display for a given path, on both client and server-side.
 | 
			
		||||
	app.Route("/", &hello{})
 | 
			
		||||
 | 
			
		||||
	// Once the routes set up, the next thing to do is to either launch the app
 | 
			
		||||
	// or the server that serves the app.
 | 
			
		||||
	//
 | 
			
		||||
	// When executed on the client-side, the RunWhenOnBrowser() function
 | 
			
		||||
	// launches the app,  starting a loop that listens for app events and
 | 
			
		||||
	// executes client instructions. Since it is a blocking call, the code below
 | 
			
		||||
	// it will never be executed.
 | 
			
		||||
	//
 | 
			
		||||
	// When executed on the server-side, RunWhenOnBrowser() does nothing, which
 | 
			
		||||
	// lets room for server implementation without the need for precompiling
 | 
			
		||||
	// instructions.
 | 
			
		||||
	app.RunWhenOnBrowser()
 | 
			
		||||
 | 
			
		||||
	// Finally, launching the server that serves the app is done by using the Go
 | 
			
		||||
	// standard HTTP package.
 | 
			
		||||
	//
 | 
			
		||||
	// The Handler is an HTTP handler that serves the client and all its
 | 
			
		||||
	// required resources to make it work into a web browser. Here it is
 | 
			
		||||
	// configured to handle requests with a path that starts with "/".
 | 
			
		||||
	http.Handle("/", &app.Handler{
 | 
			
		||||
		Name:        "Hello",
 | 
			
		||||
		Description: "An Hello World! example",
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	if err := http.ListenAndServe(":8000", nil); err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user