Categorygithub.com/showurl/zeroapi
modulepackage
0.0.0-20220810070106-b2d3da9eedb8
Repository: https://github.com/showurl/zeroapi.git
Documentation: pkg.go.dev

# README

zeroapi

go-zero通用的api 让你不需要写api服务

示例

hello

http 响应拦截

详细代码 handler.go

package zeroapi

func (h *Handler) defaultResponseHandler(in proto.Message) (code int, msg string, data interface{}) {
	if in == nil {
		return 0, "", nil
	} else {
		message, ok := in.(*dynamic.Message)
		if ok {
			if cod, exist := protoMessageValue(message, "errCode", 0); exist {
				code = int(InterfaceToInt64(cod))
			}
			if failedReason, exist := protoMessageValue(message, "failedReason", ""); exist && failedReason != "" {
				msg = failedReason.(string)
				if code == 0 {
					code = -1
				}
			}
			data = in
			return
		}
		return 0, "", in
	}
}

http header 转 proto参数

详细代码 requestparser.go

_ = dm.TrySetFieldByName("ip", r.Header.Get("X-Real-IP"))

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
Copy creates a deep copy of whatever is passed to it and returns the copy in an interface{}.
No description provided by the author
No description provided by the author
No description provided by the author
Iface is an alias to Copy; this exists for backwards compatibility reasons.
No description provided by the author
No description provided by the author
No description provided by the author
WithHeaderProcessor sets a processor to process request headers.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Interface for delegating copy process to type.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author