Skip to content

houssemFat/giny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

giny

a tiny go framework (learning purpose) usage

package main

import (
  "giny"
  "fmt"
  //"net/http"
  "./api"
)

func main() {
    fmt.Println("starting server on port 8000")
    //
    app := giny.NewApplication ()
    /**
     * Register route
     */
    base := giny.NewRouter ()
    // register
    app.RegisterRouter ("/api", api.GetUserRouter())

    app.RegisterRouter ("/", base);

    // finally start your application
    app.Run ()
}

Application

  giny.NewApplication ()

Register a route to application

  giny.RegisterRouter (path, router)

Router

initalisation

  giny.NewRouter ()

attach event

router.On(path, func (w http.ResponseWriter, request *http.Request, params map[string]string))

/**
 * get item based in id
 * @param w
 * @param request
 * @param params map[string]string , dictionary of key, value
 */
var GetItem = func (w http.ResponseWriter, request *http.Request, params map[string]string){
  url := "http://jsonplaceholder.typicode.com/comments?postId=" + params ["id"]
  response := giny.GetJsonServerResponse(url)
  // id, err := strconv.Atoi(params["id"])
  giny.SendJsonResponse (w,  response)
}
// attach the event
// here the path will match base/item/50
  router.On ("/item/:id", GetItem)

Utils

sending json response

  giny.SendJsonResponse (w,  data string)

About

golang sample framework (flask, Slim ...)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages