json

package
v0.0.0-...-8d3c269 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 4 Imported by: 0

README

Util 🧩 JSON

Send JSON Responses

Usage :

Import it to your code 🔠

    import (
        alfJSON "github.com/PiterWeb/Alf-Router/utils/json"
    )

Create your custom Struct or a Map

    type MyCustomResponse struct {
        Message string
    }

Start sending JSON across your API Endpoints

    err := alf.App(&alf.AppConfig{
    	Port: "3000",
    	Routes: alf.CreateRouter([]alf.Route{
    		{
				Path: "/api",
				Handle: func(ctx *alf.Ctx) error {

					_, err := alfJSON.JSON(ctx, MyCustomResponse{
                        Message: "Hello World",
                    })

					return err
				},
				Method: "get",
			},
    	}),
    })

	if err != nil {
		panic(err)
	}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshall

func Marshall(ctx *alf.Ctx, data interface{}) (int, error)

func Unmarshall

func Unmarshall(data []byte, v interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL