mo2errors

package
v0.0.0-...-bef4ad1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	Mo2NoError        = 200
	Mo2NoExist        = 400
	Mo2Unauthorized   = 401
	Mo2NotFound       = 404
	Mo2Conflict       = 409
	Mo2LengthRequired = 411
	Mo2Error          = 418
	Mo2NoLogin        = 420
)

Variables

This section is empty.

Functions

func CodeText

func CodeText(code int) string

CodeText returns a text for the HTTP status code. It returns the empty string if the code is unknown.

Types

type Mo2Errors

type Mo2Errors struct {
	ErrorCode int
	ErrorTip  string
}

Mo2Errors standard mo2 err

func Init

func Init(c int, format string, a ...interface{}) Mo2Errors

Init init with code and tip

func InitError

func InitError(err error) Mo2Errors

InitError init with error

func InitNoError

func InitNoError(format string, a ...interface{}) Mo2Errors

InitNoError init with no error tips

func New

func New(c int, s string) *Mo2Errors

New returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.

Example
package main

import (
	"fmt"

	"github.com/Monkey-Mouse/mo2/mo2utils/mo2errors"
)

func main() {
	err := mo2errors.New(mo2errors.Mo2LengthRequired, "abc")
	if err != nil {
		fmt.Print(err)
	}
}
Output:

411: abc

func NewCode

func NewCode(c int) *Mo2Errors

NewCode returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.

Example
package main

import (
	"fmt"

	"github.com/Monkey-Mouse/mo2/mo2utils/mo2errors"
)

func main() {
	err := mo2errors.NewCode(mo2errors.Mo2LengthRequired)
	if err != nil {
		fmt.Print(err)
	}
}
Output:

411: length not match required

func (Mo2Errors) Error

func (e Mo2Errors) Error() string

func (*Mo2Errors) Init

func (e *Mo2Errors) Init(c int, format string, a ...interface{})

Init init with code and tip

func (*Mo2Errors) InitCode

func (e *Mo2Errors) InitCode(c int)

InitCode init with code

func (*Mo2Errors) InitError

func (e *Mo2Errors) InitError(err error)

InitError init with error

func (*Mo2Errors) InitNoError

func (e *Mo2Errors) InitNoError(format string, a ...interface{})

InitNoError init with no error tips

func (Mo2Errors) IsError

func (e Mo2Errors) IsError() (error bool)

IsError as name

func (*Mo2Errors) SetErrorTip

func (e *Mo2Errors) SetErrorTip(s string)

SetErrorTip as name

Jump to

Keyboard shortcuts

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