Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

## My Go Framework

Just a hobby. I tried something and it worked.

## Example

```go
package main

import (
"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()
}

```