util

package
v0.0.0-...-263eb77 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanPath

func CleanPath(p string) string

CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.

The following rules are applied iteratively until no further processing can be done:

  1. Replace multiple slashes with a single slash.
  2. Eliminate each . path name element (the current directory).
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.

If the result of this process is an empty string, "/" is returned.

func Dir

func Dir(root string, listDirectory bool) http.FileSystem

Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally in router.Static(). in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.

Types

type Error

type Error struct {
	Err  error
	Type ErrorType
	Meta interface{}
}

func (*Error) Error

func (msg *Error) Error() string

Error implements the error interface.

func (*Error) IsType

func (msg *Error) IsType(flags ErrorType) bool

func (*Error) JSON

func (msg *Error) JSON() interface{}

func (*Error) MarshalJSON

func (msg *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*Error) SetMeta

func (msg *Error) SetMeta(data interface{}) *Error

func (*Error) SetType

func (msg *Error) SetType(flags ErrorType) *Error

type ErrorMsgs

type ErrorMsgs []*Error

func (ErrorMsgs) ByType

func (a ErrorMsgs) ByType(typ ErrorType) ErrorMsgs

ByType returns a readonly copy filtered the byte. ie ByType(util.ErrorTypePublic) returns a slice of errors with type = ErrorTypePublic.

func (ErrorMsgs) Errors

func (a ErrorMsgs) Errors() []string

Errors returns an array will all the error messages. Example:

c.Error(errors.New("first"))
c.Error(errors.New("second"))
c.Error(errors.New("third"))
c.Errors.Errors() // == []string{"first", "second", "third"}

func (ErrorMsgs) JSON

func (a ErrorMsgs) JSON() interface{}

func (ErrorMsgs) Last

func (a ErrorMsgs) Last() *Error

Last returns the last error in the slice. It returns nil if the array is empty. Shortcut for errors[len(errors)-1].

func (ErrorMsgs) MarshalJSON

func (a ErrorMsgs) MarshalJSON() ([]byte, error)

func (ErrorMsgs) String

func (a ErrorMsgs) String() string

type ErrorType

type ErrorType uint64
const (
	ErrorTypeBind    ErrorType = 1 << 63 // used when c.Bind() fails
	ErrorTypeRender  ErrorType = 1 << 62 // used when c.Render() fails
	ErrorTypePrivate ErrorType = 1 << 0
	ErrorTypePublic  ErrorType = 1 << 1

	ErrorTypeAny ErrorType = 1<<64 - 1
	ErrorTypeNu            = 2
)

type Map

type Map map[string]interface{}

type OnlyfilesFS

type OnlyfilesFS struct {
	// contains filtered or unexported fields
}

func (OnlyfilesFS) Open

func (fs OnlyfilesFS) Open(name string) (http.File, error)

Open conforms to http.Filesystem.

Jump to

Keyboard shortcuts

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