Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(v ...interface{})
- func Download(h http.Header, url, path string) (int64, error)
- func Error(v ...interface{})
- func Fatal(v ...interface{})
- func Info(v ...interface{})
- func Warn(v ...interface{})
- func WriteFile(path string, src io.Reader) (int64, error)
- type JSONPod
- func (j *JSONPod) Get(url string, h http.Header) error
- func (j *JSONPod) Open(path string) error
- func (j *JSONPod) Parse(b []byte) error
- func (j *JSONPod) Post(url string, h http.Header) (*http.Response, error)
- func (j *JSONPod) Put(url string, h http.Header) (*http.Response, error)
- func (j *JSONPod) Send(method, url string, h http.Header) (*http.Response, error)
- func (j *JSONPod) Serve(w http.ResponseWriter, code int) error
- func (j *JSONPod) ServeGzip(w http.ResponseWriter, code int) error
- func (j *JSONPod) Write(w io.Writer) error
- func (j *JSONPod) WriteFile(path string) error
- type LTag
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Flags(f int) *Logger
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Level(lv int) *Logger
- func (l *Logger) Output(out io.Writer) *Logger
- func (l *Logger) Prefix(p string) *Logger
- func (l *Logger) Tags(t LTag) *Logger
- func (l *Logger) Warn(v ...interface{})
Constants ¶
const ( Lfatal = 1 << iota Lerror Lwarn Linfo Ldebug Lall = Lfatal | Lerror | Lwarn | Linfo | Ldebug )
The levels define whether a Logger should generate logs in different level
Variables ¶
var ( // DefaultLogTag is a LTag with default strings DefaultLogTag = LTag{"FATAL:", "ERROR:", "WARN :", "INFO :", "DEBUG:"} // BracketLogTag is a LTag with "[...]" style BracketLogTag = LTag{"[FATAL]", "[ERROR]", "[WARN ]", "[INFO ]", "[DEBUG]"} )
Functions ¶
Types ¶
type JSONPod ¶
type JSONPod struct {
// contains filtered or unexported fields
}
A JSONPod is embedded with a pointer to interface. It is used to deal with JSON-encoding data.
func JSON ¶
func JSON(v interface{}) *JSONPod
JSON returns a pointer to JSONPod which embeded with v. If v is nil or not a pointer, an error may returned when calling methods of JSONPod.
func (*JSONPod) Get ¶
Get parses the JSON-encoded data from specified URL with given header and stores it in j. If the h is nil, a default http.Header is applied. "application/json" is appended to Accept header automatically.
func (*JSONPod) Send ¶
Send issues a HTTP request to specified url with given method and header. The request's body is JSON-encoded data of j.v. A http.Response is returned. It is the caller's responsibility to close the response's Body.
func (*JSONPod) Serve ¶
func (j *JSONPod) Serve(w http.ResponseWriter, code int) error
Serve responses with JSON-encoded data of j.v to client by given status code. The Content-Type header is set to "application/json; charset=utf-8". Additional response headers must be set before calling Serve.
func (*JSONPod) ServeGzip ¶
func (j *JSONPod) ServeGzip(w http.ResponseWriter, code int) error
ServeGzip is equivalent to j.Serve() which response body is compressed in gzip format.
type LTag ¶
type LTag struct {
Fatal, Error, Warn, Info, Debug string
}
A LTag is a set of strings which identify the severity level of each log
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger wraps a pointer to log.Logger and additional fields. It prints level tag and the log if severity level meets its configuration.
func NewLogger ¶
func NewLogger() *Logger
NewLogger returns a new Logger. By default, it logs at all level and the output destination is standard output
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug writes debug tag and v to output
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error writes error tag and v to output
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal calls os.Exit(1) after writes fatal tag and v to output
func (*Logger) Flags ¶
Flags sets the flags of the Logger. The flag follows the standard package "log"