Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/electrikmilk/geeves
Serves the web 🤵
https://github.com/electrikmilk/geeves
golang golang-package web-framework
Last synced: 12 days ago
JSON representation
Serves the web 🤵
- Host: GitHub
- URL: https://github.com/electrikmilk/geeves
- Owner: electrikmilk
- License: gpl-2.0
- Created: 2022-06-25T17:37:33.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-05T03:43:40.000Z (almost 2 years ago)
- Last Synced: 2024-06-20T02:05:11.717Z (7 months ago)
- Topics: golang, golang-package, web-framework
- Language: Go
- Homepage: https://pkg.go.dev/github.com/electrikmilk/geeves
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Geeves
Go web framework
### Features
- Serve static files
- Create routes at a specific url and request method and serve a file in response.
- Create a route controller and process the request and write a response by serving a file, redirecting or directly outputting something.
- Helper functions for outputting in web specific encoding formats (HTML, JSON, XML).
- Helper functions for standard logging (info, warning, success, error) in a similar format and corresponding colors. You can also format a string to be outputted in one of the defined colors
- View templates## Usage
```go
import "github.com/electrikmilk/geeves"func main() {
geeves.Init("3000")
}
```### Defaults
Set static content directory:
```go
geeves.Dir = "public" // default: "static"
```Set path to start at:
```go
geeves.Root = "/my-geeves-site/" // default: "/"
```### Routes
Create a route to serve a static file:
```go
geeves.Static("home","/","index.html") // defaults to GET method and serves file
```Create a route controller and serve a processed response:
```go
// Get(), Post(), Patch(), Put(), Delete()
geeves.Get("api", "/api", func(writer http.ResponseWriter, request *http.Request) {
var response map[string]any
response = make(map[string]any)
response["status"] = "success"
response["message"] = "Hello from API!"
geeves.Jprint(writer, response)
})
```Redirect to a custom URL or by a route name:
```go
geeves.Redirect(writer, request, "/url")
geeves.Redirect(writer, request, "home") // redirects to url for "home" route
```Get the URL of a route:
```go
geeves.RouteUrl("home") // returns "/"
```### Output
Output in HTML encoding:
```go
geeves.Output(writer, "Output...")
geeves.Outputf(writer, "%s...", variable)
```Encode and output any type of variable in JSON:
```go
var response map[string]any
response = make(map[string]any)
response["message"] = "Hello"
geeves.Jprint(writer, response)response := [...]string{"one", "two", "three"}
geeves.Jprint(writer, response)
```Output directly in an encoding:
```go
geeves.Eprint(writer, geeves.HTMLEncoding|JSONEncoding|XMLEncoding, "content")
geeves.Eprintf(writer, geeves.HTMLEncoding|JSONEncoding|XMLEncoding, "%s...", variable)
```Log helper functions:
```go
geeves.Log(geeves.FYI|WARN|GOOD|BAD, "Label", "My log message")
geeves.Logf(geeves.FYI|WARN|GOOD|BAD, "Label", "My log message: %s", variable)
// FYI = BLUE, WARN = YELLOW, GOOD = GREEN, BAD = REDfmt.Println(Color("string", geeves.Pigment))
// Pigments: RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, GRAY|GREY, WHITE
// alias: Colour()
```**Note:** `BAD` type log calls `Fatal()` or `Fatalf()` which kills the server.