Categorygithub.com/go-shafaq/gin
repositorypackage
0.0.0-20240422171821-33105a393c3e
Repository: https://github.com/go-shafaq/gin.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

Gin Web Framework

forked from github.com/gin-gonic/gin

Added future:

casting names automatically if needed

no more tagging every single field to specify its name

Basic Usage

Installation

go get github.com/go-shafaq/gin

Code

Here is a minimal example.

package main

import (
	"fmt"
	"github.com/go-shafaq/defcase"
	"github.com/go-shafaq/gin"
	"github.com/go-shafaq/gin/ginS"
)

func main() {
	// Get Public Default case
	dcase := defcase.Get()
	// Set a cases for specific packages with some tags <"*" means any package>
	dcase.SetCase("json", "*", defcase.Snak_case)
	dcase.SetCase("form", "*", defcase.Snak_case)

	// Set a Default_Case to library
	gin.SetDefCase(dcase)

	users := map[int]*User{
		1: {
			UserId: 1,
			Name:   "Diyor",
		},
	}

	ginS.POST("/", func(c *gin.Context) {
		var user User
		c.Bind(&user)

		users[user.UserId] = &user
		c.String(200, fmt.Sprintf(
			"ID of %s is %d\n", user.Name, user.UserId))
	})
	ginS.GET("/", func(c *gin.Context) {
		arr := make([]*User, 0)
		for _, user := range users {
			arr = append(arr, user)
		}

		c.JSON(200, arr)
	})

	ginS.Run()
}

type User struct {
	UserId int
	Name   string
}

Terminal HTTP requests

post by json

 curl -X POST -H "Content-Type: application/json" \
     -d '{"user_id": 2, "name": "Baxtiyor"}' \
     http://localhost:8080/

post by form

curl -X POST \
  -F "user_id=3" \
  -F "name=Firdavs" \
  http://localhost:8080/

get list

curl http://localhost:8080/