interceptor

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Copyright 2025 me.fndo.xb

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear clear all interceptors Mainly used for test environment

func Register

func Register(i Interceptor)

Register register global interceptor Interceptors are executed in registration order

Example:

interceptor.Register(&LoggingInterceptor{})
interceptor.Register(&PrometheusInterceptor{})

func Unregister

func Unregister(name string)

Unregister uninstall interceptor (by name)

Example:

interceptor.Unregister("logging")

Types

type Interceptor

type Interceptor interface {
	// Name interceptor name (for registration/unregistration)
	Name() string

	// BeforeBuild before Build() is executed
	// ⭐ Only pass Metadata, enforced at compile time to only set metadata
	// ⭐ Cannot modify query logic (type system ensures)
	// Return error can prevent Build()
	BeforeBuild(meta *Metadata) error

	// AfterBuild after Build() is executed
	// Used for observing generated SQL (logging, monitoring, auditing)
	// Return error can prevent subsequent execution
	AfterBuild(built interface{}) error
}

Interceptor interceptor interface Used for infrastructure observation (logging, monitoring) Not used for business logic

func GetAll

func GetAll() []Interceptor

GetAll get all interceptors (read only) Mainly used for internal use

type Metadata

type Metadata struct {
	// Trace related
	TraceID   string `json:"trace_id,omitempty"`
	RequestID string `json:"request_id,omitempty"`

	// User related
	UserID   int64 `json:"user_id,omitempty"`
	TenantID int64 `json:"tenant_id,omitempty"`

	// Performance related
	StartTime time.Time `json:"start_time,omitempty"`

	// Extension point (custom metadata)
	Custom map[string]interface{} `json:"custom,omitempty"`
}

Metadata query metadata Does not affect query logic, only for observation

func (*Metadata) Get

func (m *Metadata) Get(key string) interface{}

Get get custom metadata

func (*Metadata) GetBool

func (m *Metadata) GetBool(key string) bool

GetBool get bool type metadata

func (*Metadata) GetFloat64

func (m *Metadata) GetFloat64(key string) float64

GetFloat64 get float64 type metadata

func (*Metadata) GetInt64

func (m *Metadata) GetInt64(key string) int64

GetInt64 get int64 type metadata

func (*Metadata) GetString

func (m *Metadata) GetString(key string) string

GetString get string type metadata

func (*Metadata) Set

func (m *Metadata) Set(key string, value interface{})

Set set custom metadata

Jump to

Keyboard shortcuts

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