feat: add initial Go+HTMX web project structure
This commit is contained in:
		
							
								
								
									
										26
									
								
								cmd/web/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								cmd/web/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | package main | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"net/http" | ||||||
|  | 	"os" | ||||||
|  | 	 | ||||||
|  | 	"github.com/go-chi/chi/v5" | ||||||
|  | 	"github.com/go-chi/chi/v5/middleware" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func main() { | ||||||
|  | 	r := chi.NewRouter() | ||||||
|  | 	r.Use(middleware.Logger) | ||||||
|  | 	 | ||||||
|  | 	// Setup routes | ||||||
|  | 	r.Get("/", handleHome) | ||||||
|  | 	 | ||||||
|  | 	port := ":3000" | ||||||
|  | 	fmt.Printf("Starting server on %s\n", port) | ||||||
|  | 	err := http.ListenAndServe(port, r) | ||||||
|  | 	if err != nil { | ||||||
|  | 		fmt.Println(err) | ||||||
|  | 		os.Exit(1) | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										8
									
								
								go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								go.mod
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | module myhtmxapp | ||||||
|  |  | ||||||
|  | go 1.21 | ||||||
|  |  | ||||||
|  | require ( | ||||||
|  | 	github.com/go-chi/chi/v5 v5.0.12 | ||||||
|  | 	github.com/go-chi/render v1.0.3 | ||||||
|  | ) | ||||||
							
								
								
									
										11
									
								
								handlers/handlers.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								handlers/handlers.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | package handlers | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"html/template" | ||||||
|  | 	"net/http" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func HandleHome(w http.ResponseWriter, r *http.Request) { | ||||||
|  | 	tmpl := template.Must(template.ParseFiles("templates/public/index.html")) | ||||||
|  | 	tmpl.Execute(w, nil) | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								templates/public/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								templates/public/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="en"> | ||||||
|  | <head> | ||||||
|  | 	<meta charset="UTF-8"> | ||||||
|  | 	<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|  | 	<title>HTMX + Go Starter</title> | ||||||
|  | 	<script src="https://unpkg.com/htmx.org@1.9.10"></script> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | 	<h1>HTMX + Go Starter</h1> | ||||||
|  | 	<p>Edit this HTML in templates/public/index.html</p> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder (aider)
					Grail Finder (aider)