Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aligoren/mygoframework
Extremely unnecessary Golang framework.
https://github.com/aligoren/mygoframework
Last synced: 2 days ago
JSON representation
Extremely unnecessary Golang framework.
- Host: GitHub
- URL: https://github.com/aligoren/mygoframework
- Owner: aligoren
- Created: 2022-07-08T19:34:27.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-07-08T21:31:43.000Z (over 2 years ago)
- Last Synced: 2023-03-01T04:03:01.634Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## My Go Framework
Just a hobby. I tried something and it worked.
## Example
```go
package mainimport (
"log"
"mygoframework"
"net/http"
)func main() {
app, err := mygoframework.New(mygoframework.MyConfig{
Name: "MyApp",
Addr: ":8080",
})if err != nil {
log.Fatal(err)
}app.Get("/", func(ctx *mygoframework.Context) error {
return ctx.SendString("Hello world!")
})app.Get("/user/:id", func(ctx *mygoframework.Context) error {
return ctx.SetStatus(http.StatusNotFound).SendString("world 1")
})app.Get("/json/:id", func(ctx *mygoframework.Context) error {
id, _ := ctx.Param("id")
return ctx.SetStatus(http.StatusBadGateway).SendJson(mygoframework.J{
"id": id,
"name": "Ali",
})
})app.Get("/xml/:id", func(ctx *mygoframework.Context) error {
id, _ := ctx.Param("id")
type ExtraData struct {
Name string
}type User struct {
ID string
Data ExtraData
}user := User{
ID: id,
Data: ExtraData{
Name: "Ali",
},
}return ctx.SetStatus(http.StatusOK).SendXml(user)
})app.Start()
}```