first commit
This commit is contained in:
commit
45640416cd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
output.css
|
||||
config.json
|
3
config.example.json
Normal file
3
config.example.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"port": 8787
|
||||
}
|
21
license
Normal file
21
license
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) [2024] [OceanSlim]
|
||||
|
||||
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.
|
33
main.go
Normal file
33
main.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"GoStart/src/api"
|
||||
"GoStart/src/routes"
|
||||
"GoStart/src/util"
|
||||
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
// Load Configurations
|
||||
cfg, err := util.LoadConfig()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to load config: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
// Initialize Home View
|
||||
mux.HandleFunc("/", routes.RootHandler)
|
||||
// Serve Static Files
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
||||
// Example view
|
||||
mux.HandleFunc("/example", routes.ExampleHandler)
|
||||
// API endpoint
|
||||
mux.HandleFunc("/api/example", api.ExampleHandler)
|
||||
|
||||
fmt.Printf("Server is running on http://localhost:%d\n", cfg.Port)
|
||||
http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), mux)
|
||||
}
|
46
readme.md
Normal file
46
readme.md
Normal file
@ -0,0 +1,46 @@
|
||||
# GoStart
|
||||
|
||||
This is a basic starter project for building web applications using Go, Tailwind CSS, and htmx. It provides a foundation for creating interactive and responsive web applications without relying on any third-party dependencies, utilizing only the packages included with the Go language by default.
|
||||
|
||||
## Features
|
||||
|
||||
- **Go**: The project is built using Go, a powerful and efficient programming language for building scalable and high-performance applications.
|
||||
- **Tailwind CSS**: Tailwind CSS is used for styling the web application, providing a utility-first CSS framework that enables rapid UI development.
|
||||
- **htmx**: htmx is a lightweight library that allows you to add interactive features to your web pages without writing JavaScript, enabling server-side rendering and reducing the need for complex client-side code.
|
||||
- **Bring Your Own Database**: This starter project does not include a specific database implementation, allowing you to choose and integrate the database solution that best fits your project's requirements.
|
||||
|
||||
### Getting Started
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```bash
|
||||
git clone https://git.happytavern.co/oceanslim/gostart.git
|
||||
```
|
||||
|
||||
2. Navigate to the project directory:
|
||||
|
||||
```bash
|
||||
cd GoStart
|
||||
```
|
||||
|
||||
3. Setup your configuration
|
||||
|
||||
```bash
|
||||
cp config.example.json config.json
|
||||
```
|
||||
|
||||
4. Build and run the application:
|
||||
|
||||
```bash
|
||||
go run main.go
|
||||
```
|
||||
|
||||
The application will be accessible at `http://localhost:8787`, or whatever port you set in your configuration.
|
||||
|
||||
### Contributing
|
||||
|
||||
Contributions to this project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the [MIT License](LICENSE).
|
36
src/api/api.go
Normal file
36
src/api/api.go
Normal file
@ -0,0 +1,36 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ExampleHandler is a basic HTTP handler function for your API endpoint
|
||||
func ExampleHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Define your response struct
|
||||
type Response struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// Create a response object
|
||||
response := Response{
|
||||
Message: "Hello, this is a basic example API!",
|
||||
}
|
||||
|
||||
// Convert response object to JSON
|
||||
jsonResponse, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Set response headers
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
// Write the JSON response
|
||||
_, err = w.Write(jsonResponse)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
7
src/routes/example.go
Normal file
7
src/routes/example.go
Normal file
@ -0,0 +1,7 @@
|
||||
package routes
|
||||
|
||||
import "net/http"
|
||||
|
||||
func ExampleHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "web/views/example.html")
|
||||
}
|
27
src/routes/root.go
Normal file
27
src/routes/root.go
Normal file
@ -0,0 +1,27 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type PageData struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
func RootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := PageData{
|
||||
Title: "Home Page",
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles("web/views/index.html")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
28
src/util/config.go
Normal file
28
src/util/config.go
Normal file
@ -0,0 +1,28 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port int `json:"port"`
|
||||
Development string `json:"development"`
|
||||
}
|
||||
|
||||
func LoadConfig() (*Config, error) {
|
||||
file, err := os.Open("config.json")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open config file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var config Config
|
||||
err = json.NewDecoder(file).Decode(&config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode config file: %v", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
1
web/static/htmx.min.js
vendored
Normal file
1
web/static/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
web/static/img/favicon.ico
Normal file
BIN
web/static/img/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
BIN
web/static/img/globe.png
Normal file
BIN
web/static/img/globe.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
5
web/style/input.css
Normal file
5
web/style/input.css
Normal file
@ -0,0 +1,5 @@
|
||||
@config "tailwind.config.js";
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
9
web/style/readme.md
Normal file
9
web/style/readme.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Development
|
||||
|
||||
For Tailwind to Rebuild the Output CSS, a watcher must be run to compile the new styling as pages are edited.
|
||||
|
||||
To do this run:
|
||||
|
||||
```bash
|
||||
tailwindcss -i web/style/input.css -o web/static/output.css --watch
|
||||
```
|
10
web/style/tailwind.config.js
Normal file
10
web/style/tailwind.config.js
Normal file
@ -0,0 +1,10 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["./**/*.{html,js}"],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
27
web/views/example.html
Normal file
27
web/views/example.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Example Route</title>
|
||||
<link rel="stylesheet" href="/static/output.css" />
|
||||
<link rel="icon" href="/static/img/favicon.ico" type="image/x-icon" />
|
||||
</head>
|
||||
<body class="text-center text-blue-400 bg-gray-800">
|
||||
<header>
|
||||
<h1 class="mt-8 mb-8 text-3xl font-bold text-blue-300">
|
||||
This is an additional example route
|
||||
</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section>
|
||||
<h1 class="font-bold">Serve Static Files Like this Globe</h1>
|
||||
<img src="/static/img/globe.png" alt="alternate text">
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© 2024 My Web App</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
41
web/views/index.html
Normal file
41
web/views/index.html
Normal file
@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>GO Web App</title>
|
||||
<link rel="stylesheet" href="/static/output.css" />
|
||||
<link rel="icon" href="/static/img/favicon.ico" type="image/x-icon" />
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
</head>
|
||||
<body class="text-center text-blue-300 bg-gray-800">
|
||||
<header>
|
||||
<h1 class="mt-8 mb-8 text-3xl font-bold text-blue-400">
|
||||
Welcome to My GO Web App Framework {{.Title}}
|
||||
</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section>
|
||||
<button
|
||||
hx-get="/api/example"
|
||||
class="p-2 text-white bg-blue-400 rounded-md"
|
||||
>
|
||||
Click Me!
|
||||
</button>
|
||||
<h1 class="font-bold">API Example</h1>
|
||||
<a href="/api/example" target="_blank">Access Example API</a>
|
||||
<h2>Content Section</h2>
|
||||
<p>
|
||||
This is the main content of your web app. You can add any HTML content
|
||||
here.
|
||||
</p>
|
||||
<a href="/example">Another Example Route can be found here</a>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© 2024 My Web App</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user