utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright 2025 HAProxy Technologies LLC

Licensed 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 AliasImport

func AliasImport(importPath string) string

AliasImport applies AliasPkg to the last path segment of an import path.

func AliasPkg

func AliasPkg(pkg string) string

AliasPkg converts a package name to a valid Go import alias. - Replaces hyphens with underscores. - If the name starts with a digit, prefixes it with an underscore. - Returns an empty string if no alias is necessary.

func DiffFuncName

func DiffFuncName(input string) string

DiffFuncName returns the generated Diff function name for a given type name.

func EqualFuncName

func EqualFuncName(input string) string

EqualFuncName returns the generated Equal function name for a given type name.

func ExtractPkg

func ExtractPkg(fullpkg string) string

ExtractPkg returns the last element of a full Go import path, which corresponds to the package name (e.g., "github.com/foo/bar" -> "bar").

func Fqn

func Fqn(packagedName string) string

Fqn generates a "Fully Qualified Name"-like string from a Go type name, transforming it into a form suitable for use in generated function names. It handles slices, arrays, and pointers by replacing symbols with descriptive words (e.g., []MyType -> SliceMyType, **MyType -> PointerPointerMyType).

func GenerateAliasVarName

func GenerateAliasVarName(packagedType string) string

GenerateAliasVarName converts a packaged type name like "models.Backend" or "v1.Backend" into a variable-safe Go identifier like "modelsBackend" or "v1Backend". Non-letter and non-digit characters are removed.

func HasDiffFor

func HasDiffFor(typ reflect.Type) (hasDiff bool, hasDiffWithOpts bool)

HasDiffFor checks whether a given type defines a Diff method with the exact signature: func (T) Diff(T) map[string][]interface{} or func (T) Diff(T, opts ...GoMethodGenOptions) map[string][]interface{}.

func HasEqualFor

func HasEqualFor(typ reflect.Type) (hasEqual bool, hasEqualWithOpts bool)

HasEqualFor checks whether a given type defines an Equal method with the exact signature: func (T) Equal(T) bool or func (T) Equal(T, opts ...GoMethodGenOptions) bool

func SerializeJSON

func SerializeJSON[T any](node T) string

SerializeJSON serializes any Go value to a pretty-printed JSON string. If serialization fails, the program will log a fatal error and exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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