标签:实现 ica for style golang class func err fun
package builtin
type error interface { Error() string }
######################
error接口定义
package errors // 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. func New(text string) error { return &errorString{text} } // errorString is a trivial implementation of error. type errorString struct { s string } func (e *errorString) Error() string { return e.s }
######################################################
1.定义一个包含一个字符串的类errorString,并实现erro接口方法
2.创建一个errorString对象
package http
var ( ErrBodyNotAllowed = errors.New("http: request method or response status code does not allow body") ErrHijacked = errors.New("http: connection has been hijacked") ErrContentLength = errors.New("http: wrote more than the declared Content-Length") ErrWriteAfterFlush = errors.New("unused") )
########################################################################################################
erro使用:
直接使用errors包的New方法创建
标签:实现 ica for style golang class func err fun
原文地址:https://www.cnblogs.com/igoodful/p/12804272.html