Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aliuygur/gores

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gores

http response utility library for GO

installation

go get github.com/alioygur/gores

use

package main

import (
	"log"
	"net/http"

	"github.com/alioygur/gores"
)

type User struct {
	Name  string
	Email string
	Age   int
}

func StringResponse(w http.ResponseWriter, r *http.Request) {
	gores.String(w, http.StatusOK, "Hello World")
}

func HTMLResponse(w http.ResponseWriter, r *http.Request) {
	gores.HTML(w, http.StatusOK, "<h1>Hello World</h1>")
}

func JSONResponse(w http.ResponseWriter, r *http.Request) {
	user := User{Name: "Ali", Email: "[email protected]", Age: 28}
	gores.JSON(w, http.StatusOK, user)
}

func main() {
	http.HandleFunc("/", StringResponse)
	http.HandleFunc("/html", HTMLResponse)
	http.HandleFunc("/json", JSONResponse)

	err := http.ListenAndServe(":8000", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

for more documentation godoc

TODO

  • add file response
  • write tests

Contribute

Use issues for everything

  • Report problems
  • Discuss before sending a pull request
  • Suggest new features/recipes
  • Improve/fix documentation

Thanks & Authors

I use code/got inspiration from these excellent libraries:

About

Go package that handles HTML, JSON, XML and etc. responses

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages