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.
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.
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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) GetFloat64 ¶
GetFloat64 get float64 type metadata