Skip to content

insanXYZ/mapes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

Installation

go get github.com/insanXYZ/mapes

Example

package main

import (
	"fmt"
	"github.com/insanXYZ/mapes"
)

type CreateUser struct {
	Name    string `form:"name"`
	Address string `param:"address"`
	Email   string `query:"email"`
}

func main() {
	//mapes instance
	m := mapes.New()

	m.Get("/", func(ctx *mapes.Context) error {
		return ctx.String(200, "Hello world")
	})
	
	//get parameters
	m.Get("/hello/:name/from/:address", func(ctx *mapes.Context) error {
		return ctx.String(200, fmt.Sprintf("Hello, my name is %s from %s", ctx.Param("name"), ctx.Param("address")))
	})

	//get query parameters
	//http:localhost:port/queryParams?last=yourname
	m.Get("/queryParams", func(ctx *mapes.Context) error {
		return ctx.String(200, ctx.Query("last"))
	})

	//binding with struct
	m.Post("/create-user/:address", func(ctx *mapes.Context) error {
		user := new(CreateUser)
		err := ctx.Bind(user)
		if err != nil {
			return err
		}

		return ctx.Json(200, user)
	})

	//grouping route
	group := m.Group("/api")

	group.Get("/contacts", func(ctx *mapes.Context) error {
		return ctx.Json(200, map[string]string{
			"name":  "Jhon Doe",
			"email": "[email protected]",
		})
	})

	err := m.Start(":1323")
	if err != nil {
		panic(err.Error())
	}
}

About

mapes - routing http framework

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages