util

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2019 License: Apache-2.0 Imports: 25 Imported by: 103

Documentation

Overview

Package util includes common utilities.

Index

Constants

This section is empty.

Variables

View Source
var File = myfile{}

File utilities.

View Source
var Go = mygo{}

Go utilities.

View Source
var Net = mynet{}

Network utilities.

View Source
var OS = myos{}

OS utilities.

View Source
var Rand = myrand{}

Random utilities.

View Source
var Str = str{}

String utilities.

View Source
var Zip = myzip{}

Zip utilities.

Functions

func Recover

func Recover()

Recover recovers a panic.

func RetGzJSON

func RetGzJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{})

RetGzJSON writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".

func RetGzResult

func RetGzResult(w http.ResponseWriter, r *http.Request, res *Result)

RetGzResult writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".

func RetJSON

func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{})

RetJSON writes HTTP response with "Content-Type, application/json".

func RetResult

func RetResult(w http.ResponseWriter, r *http.Request, res *Result)

RetResult writes HTTP response with "Content-Type, application/json".

Types

type Result

type Result struct {
	Succ bool        `json:"succ"` // successful or not
	Code int         `json:"code"` // return code
	Msg  string      `json:"msg"`  // message
	Data interface{} `json:"data"` // data object
}

Result.

func NewResult

func NewResult() *Result

NewResult creates a result with Succ=true, Code=0, Msg="", Data=nil.

type WSChannel

type WSChannel struct {
	Sid     string          // wide session id
	Conn    *websocket.Conn // websocket connection
	Request *http.Request   // HTTP request related
	Time    time.Time       // the latest use time
}

WSChannel represents a WebSocket channel.

func (*WSChannel) Close

func (c *WSChannel) Close()

Close closed the channel.

func (*WSChannel) ReadJSON

func (c *WSChannel) ReadJSON(v interface{}) (ret error)

ReadJSON reads the next JSON-encoded message from the channel and stores it in the value pointed to by v.

func (*WSChannel) Refresh

func (c *WSChannel) Refresh()

Refresh refreshes the channel by updating its use time.

func (*WSChannel) WriteJSON

func (c *WSChannel) WriteJSON(v interface{}) (ret error)

WriteJSON writes the JSON encoding of v to the channel.

type ZipFile

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

ZipFile represents a zip file.

func (*ZipFile) AddDirectory

func (z *ZipFile) AddDirectory(path, dirName string) error

AddDirectory adds a directory.

func (*ZipFile) AddDirectoryN

func (z *ZipFile) AddDirectoryN(path string, names ...string) error

AddDirectoryN adds directories.

func (*ZipFile) AddEntry

func (z *ZipFile) AddEntry(path, name string) error

AddEntry adds a entry.

func (*ZipFile) AddEntryN

func (z *ZipFile) AddEntryN(path string, names ...string) error

AddEntryN adds entries.

func (*ZipFile) Close

func (z *ZipFile) Close() error

Close closes the zip file writer.

Jump to

Keyboard shortcuts

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