Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sphireinc/core
A Go framework for fast API development
https://github.com/sphireinc/core
Last synced: about 1 month ago
JSON representation
A Go framework for fast API development
- Host: GitHub
- URL: https://github.com/sphireinc/core
- Owner: sphireinc
- License: mit
- Created: 2022-06-28T18:33:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T20:59:25.000Z (7 months ago)
- Last Synced: 2024-06-05T08:35:07.443Z (7 months ago)
- Language: Go
- Size: 99.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sphire Core
Core is a framework which allows for fast API prototyping. Based off of Fiber.## Setup
The (pun fully intended) *core* of Sphire Core is the `Config` struct. This is the entrypoint
of the framework, and must be instantiated as follows:var App core.Config = core.New()
Within `core.New()` (located in `factory.go`), we look at the `SPC_ENV` environment variable
which must coincide with the configuration JSON filename. If `SPC_ENV` is set to `dev` for instance
then the configuration JSON filename must be `dev.json`. By default, it uses `dev.json`.Within `New()`, the `Load()` function is called, which loads our JSON configuration into
the `Config` struct. It then proceeds to call `Factory()` which instantiates our enabled services.It is then possible to simply run `App.Run()` to start listening on our designated address:port.
The framework can run in the simple runner:
package main
import (
core "github.com/sphireinc/core/v1"
)var App := core.New()
func main() {
App.Run()
}That is all that is required.
## Routing
Routing in Core is simple. We create a function with this signature:
func handler(ctx *routing.Context) error {
body := core.Res{}
return core.HandleResponseJSON(ctx, body.Byte(), App.S.OK)
}Then, we add it to our `app` before calling `app.Run()`:
package main
import (
core "github.com/sphireinc/core/v1"
)
var App = core.New()
func main() {
App.Router.Get("/our-custom-route", handler)
App.Router.Get("/non-mantis-route", nonMantisHandler)
App.Run()
}func handler(ctx *core.Context) error {
body := core.Res{
Body: []byte(`{"x": 3}`),
BodyString: string("hello"),
}
return core.HandleResponseJSON(ctx, body.Byte(), App.S.OK)
}func nonMantisHandler(ctx *core.Context) error {
return core.HandleResponseJSON(ctx, []byte(`{}`), App.S.OK)
}That is all there is to it. Things like MySQL and Redis are set up automatically
when they find a configuration, and hang off of the `App` struct (like the Mantis logger).## Profiling / Stats View
Core utilizes the StatsView package (github.com/go-echarts/statsview) to display a quick
statistical view of memory usage etc. This can be viewed at `:18066/debug/statsview`## To Do
1. Implement FastWS (https://github.com/fasthttp/fastws)
2. Implement Proper CORS, CSRF, Limiter, etc (https://github.com/gofiber/fiber/tree/master/middleware)
3. Implement Goth (https://github.com/markbates/goth)