Go

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NonNilTypeList is a list of non-nil types.
	NonNilTypeList []string

	// NillablePrefix is a list of prefixes that indicate a type is nillable.
	NillablePrefix []string
)
View Source
var (
	// GoReservedKeywords is a list of Go reserved keywords.
	GoReservedKeywords []string
)

Functions

func FixVarNameIncremental

func FixVarNameIncremental(variable_name string, keywords []string, min int, start int) (string, bool)

FixVarNameIncremental works like FixVariableName but it appends an incremental number to the variable name instead of a suffix.

Parameters:

  • variable_name: The variable name to fix.
  • keywords: The list of keywords to check against.
  • min: The minimum length of the variable name. If less than 1, the function uses 1.
  • start: The starting number to append to the variable name. If less than 0, the function uses 0.

Returns:

  • string: The fixed variable name.
  • bool: True if the variable name is not empty. False otherwise.

func FixVariableName

func FixVariableName(variable_name string, keywords []string, min int, suffix string) (string, bool)

FixVariableName fixes the given variable name by checking whether or not the name trimmed to the minimum length is valid. If it is not valid, the function appends the given suffix to the name until a valid name is found.

Moreover, if the name is greater than the minimum length, the function first checks whether the name can be trimmed to the minimum length and still be valid. If it is not valid, the function tries the remaining characters one by one until a valid name is found. Finally, if it is still not valid, the function appends the given suffix to the name until a valid name is found.

Parameters:

  • variable_name: The variable name to fix.
  • keywords: The list of keywords to check against.
  • min: The minimum length of the variable name. If less than 1, the function uses 1.
  • suffix: The suffix to append to the variable name. If empty, the function uses "_".

Returns:

  • string: The fixed variable name.
  • bool: True if the variable name is not empty. False otherwise.

func IsValidName

func IsValidName(variable_name string, keywords []string) error

IsValidName checks if the given variable name is valid.

This function checks if the variable name is not empty and if it is not a Go reserved keyword. It also checks if the variable name is not in the list of keywords.

Parameters:

  • variable_name: The variable name to check.
  • keywords: The list of keywords to check against.

Returns:

  • error: An error if the variable name is invalid.

func MakeVariableName

func MakeVariableName(type_name string) (string, error)

MakeVariableName converts a type name to a variable name.

Parameters:

  • type_name: The type name to convert.

Returns:

  • string: The variable name.
  • error: An error if the type name is invalid.

Errors:

  • *common.ErrInvalidParameter: If the type name is empty.
  • *common.ErrAt: If the type name is invalid at a specific position.

func ParseFields

func ParseFields(str string) (map[string]string, error)

ParseFields parses the given string to extract fields and their types.

Parameters:

  • str: The string containing fields to parse.

Returns:

  • map[string]string: A map of field names to their corresponding types.
  • error: An error if parsing encounters any issues.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

type TypeNillability added in v0.3.40

type TypeNillability int8

TypeNillability is an enum for the nillability of a type.

const (
	// IsNillable indicates that the type is nillable such as a pointer or an interface.
	IsNillable TypeNillability = iota

	// IsNotNillable indicates that the type is not nillable such as an int or a string.
	IsNotNillable

	// IsUnknown indicates that the type is unknown (i.e., it can either be nillable or not).
	IsUnknown
)

func IsNonNilTypeID added in v0.3.40

func IsNonNilTypeID(id string) TypeNillability

IsNonNilTypeID checks if the given type ID is a non-nil type.

Parameters:

  • id: The type ID to check.

Returns:

  • TypeNillability: The nillability of the type ID.

func (TypeNillability) String added in v0.3.40

func (t TypeNillability) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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