Skip to content

A simple RESTful API framework for Go programming language

License

Notifications You must be signed in to change notification settings

jdroguett/grest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GRest

A simple RESTful API framework for Go programming language

Install

go get github.com/jdroguett/grest

Use

package main

import (
	"database/sql"
	"fmt"
	"io"
	"net/http"

	"github.com/jdroguett/grest"
)

//City is my resource
type City struct {
	id   int
	name string
}

//CityController is my controller
type CityController struct {
	Db *sql.DB
}

//Index is the implementation of the action.
func (city *CityController) Index(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, "CityController index\n")
}

//Show is the implementation of the action.
func (city *CityController) Show(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, fmt.Sprintf("CityController show with id == %v \n", req.Form.Get("id")))
}

//Update is the implementation of the action.
func (city *CityController) Update(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, fmt.Sprintf("CityController update with id == %v \n", req.Form.Get("id")))
}

//Create is the implementation of the action.
func (city *CityController) Create(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, "CityController create\n")
}

//Destroy is the implementation of the action.
func (city *CityController) Destroy(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, fmt.Sprintf("CityController destroy with id == %v \n", req.Form.Get("id")))
}

func main() {
	grest := grest.New()
	grest.Resources("/cities", &CityController{})
	http.ListenAndServe(":4000", nil)
}

Example

View source /example/cities.go

About

A simple RESTful API framework for Go programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published