Help us shape the future of Go! Take the 2026 Go Developer Survey

tape

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: MIT Imports: 3 Imported by: 0

README

tape

a tape of echo,iris with go

how to use

tape

tape.SUCCESS    // const 200

tape.FAIL       // const 404

tape.Map        // map[string]interface{}

tape.Hash      // struct

Exce

tape.Exce.Catch // catch exce

tape.Exce.OK    // if !ok throw exce

tape.Exce.Err   // if err!=nil throw exce
demo

Echo

func demo(ctx echo.Context) error {
	// Catch exce
	defer tape.Exce.Catch(ctx)()
	data := map[string]string{
		"go":   "golang",
		"java": "javalang",
		"rust": "rustlang",
	}
	value, ok := data["python"]
	// check ok
	tape.Exce.OK(ok, "python is not exist")
	_, err := strconv.Atoi(value)
	// check err
	tape.Exce.Err(err, "")
	result := tape.Map{
		"data": data,
	}
	// return data
	return ctx.JSON(200, tape.Hash{
		STATUS: tape.SUCCESS,
		RESULT: result,
	})
}

Iris

func demo(ctx *iris.Context) {
	// Catch exce
	defer tape.Exce.Catch(ctx)()
	data := map[string]string{
		"go":   "golang",
		"java": "javalang",
		"rust": "rustlang",
	}
	value, ok := data["python"]
	// check ok
	tape.Exce.OK(ok, "python is not exist")
	_, err := strconv.Atoi(value)
	// check err
	tape.Exce.Err(err, "")
	result := tape.Map{
		"data": data,
	}
	// return data
	ctx.JSON(200, tape.Hash{
		STATUS: tape.SUCCESS,
		RESULT: result,
	})
}

Documentation

Index

Constants

View Source
const (
	// SUCCESS show status 200 when success
	SUCCESS = 200

	// FAIL show status 404 when fail
	FAIL = 404
)

Variables

View Source
var Exce = new(Exception)

Exce exce

Functions

This section is empty.

Types

type Exception

type Exception struct{}

Exception throw exception

func (*Exception) Catch

func (e *Exception) Catch(ctx echo.Context) func()

Catch throw exception if recover err

func (*Exception) Err

func (e *Exception) Err(err error, message interface{})

Err throw exception if err!=nil

func (*Exception) OK

func (e *Exception) OK(ok bool, message interface{})

OK throw exception if !ok

type Hash

type Hash struct {
	STATUS  int         `json:"status"`            // show sataus
	RESULT  interface{} `json:"result,omitempty"`  // show result when success
	MESSAGE interface{} `json:"message,omitempty"` // show message when fail
}

Hash map

type Map

type Map map[string]interface{}

Map map

Jump to

Keyboard shortcuts

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