view

package
v0.0.0-...-7404c28 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package view provides a simple way to create HTTP handlers that implement the http.Handler interface.

Index

Constants

View Source
const (
	// BK_APIv1_CODE_KEY 蓝鲸规范返回的 code key
	BK_APIv1_CODE_KEY = "code"

	// BK_APIv1_CODE_OK_VALUE 蓝鲸规范返回正常请求的 code value
	BK_APIv1_CODE_OK_VALUE = 0
)

Variables

This section is empty.

Functions

func Generic

func Generic(authorizer auth.Authorizer) func(next http.Handler) http.Handler

Generic http 中间件, 返回蓝鲸规范的数据结构

Types

type DataStructInterface

type DataStructInterface interface {
	IsDataStruct() bool
}

DataStructInterface 判断是否已经包含 data 结构体实现, 处理 structpb.Struct 问题

type GenericFunc

type GenericFunc func(r *http.Request) (interface{}, error)

GenericFunc View函数类型, 使用view.GenericFunc(customHandler)

func (GenericFunc) ServeHTTP

func (h GenericFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handler 函数实现

type GenericResponseWriter

type GenericResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

GenericResponseWriter 自定义Write,自动补充 data 和 web_annotations 数据

func NewGenericResponseWriter

func NewGenericResponseWriter(w http.ResponseWriter, authorizer auth.Authorizer) *GenericResponseWriter

NewGenericResponseWriter GenericResponseWriter初始化

func (*GenericResponseWriter) BuildWebAnnotation

func (w *GenericResponseWriter) BuildWebAnnotation(ctx context.Context, msg proto.Message) error

BuildWebAnnotation 动态执行 webannotions 函数

func (*GenericResponseWriter) SetDataStructFlag

func (w *GenericResponseWriter) SetDataStructFlag(ok bool)

SetDataStructFlag 设置是否是 DataStruct 类型

func (*GenericResponseWriter) SetError

func (w *GenericResponseWriter) SetError(err error)

SetError 设置错误请求

func (*GenericResponseWriter) SetWriterAttrs

func (w *GenericResponseWriter) SetWriterAttrs(ctx context.Context, msg proto.Message) error

SetWriterAttrs set attributes of the writer

func (*GenericResponseWriter) Write

func (w *GenericResponseWriter) Write(data []byte) (int, error)

Write http write 接口实现

Directories

Path Synopsis
Package modifier is the interface used to modify response
Package modifier is the interface used to modify response
Package webannotation webannotation
Package webannotation webannotation

Jump to

Keyboard shortcuts

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