Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

ZhenhangTung/GoGym

Repository files navigation

GoGym

Build Status

中文文档

GoGym is a framework for building RESTful APIs, which is written in Golang. It is inspired by an artisan framework Laravel.

Icon made by @Beth Wardolf

Import Package

  • Dependencies:

     $ go get github.com/sirupsen/logrus
    
  • Install the package from the command line:

     $ go get github.com/ZhenhangTung/GoGym

How to use GoGym

1. Define your Own Controllers And Actions

type HelloController struct {
}

func (h *HelloController) SayHello(api *GoGym.Gym) {
    // Your logic goes there
}

2. Do preparations for your Gym's opening

var gym = new(GoGym.Gym)
gym.Prepare()

3. Register your controller, and make it as a part of your Gym family

gym.Router.RegisterController(&HelloController{})

4. Be ready for getting requests. Let's smile and say hello. :)

gym.Router.Get("/", "HelloController@SayHello")

5. Now your Gym are opening. Let's cheer!

gym.OpenAt(3000)

Code Example

package main

import (
	"github.com/ZhenhangTung/GoGym"
	"net/http"
)

type HelloController struct {
}

func (h *HelloController) SayHello(api *GoGym.Gym) {
	api.Response.JsonResponse(map[string]string{"msg": "Hello World!"}, 200, http.Header{})
}

func main() {
	var gym = new(GoGym.Gym)
	gym.Prepare()
	gym.Router.RegisterController(&HelloController{})
	gym.Router.Get("/", "HelloController@SayHello")
	gym.OpenAt(3000)
}

// Then open the http://localhost:3000 to see the result

API Documentation

Roadmap

  • v0.1: Receive request and send JSON response. [Finished]
  • v0.2: Support route parameters. [In development]
  • v0.3: Support using functions directly when defining routes.
  • v0.4: Support middleware.

Contribution

Your contribution to GoGym development is very welcomed! You may contribute in the following ways:

  • Post issues and feedbacks.
  • Submit fixes, features via the Pull Request.
  • Write/polish the documentation. The documentation exists in folder doc.

Contributors

Thanks for all contributors.

License

GoGym is released under the MIT License.