utils

package
v2.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadOnlyPermissions = os.FileMode(0444)
	GeneratedFileSuffix = ".gr.go"
	ManifestFile        = "go-restli-manifest.gr.json"
)
View Source
const (
	Yes = ShouldUsePointer(0)
	No  = ShouldUsePointer(1)
)
View Source
const (
	MarshalRestLi              = "MarshalRestLi"
	UnmarshalRestLi            = "UnmarshalRestLi"
	Marshal                    = "Marshal"
	Unmarshal                  = "Unmarshal"
	EncodeQueryParams          = "EncodeQueryParams"
	PopulateLocalDefaultValues = "populateLocalDefaultValues"
	Equals                     = "Equals"
	ComputeHash                = "ComputeHash"
	ValidateUnionFields        = "ValidateUnionFields"
	ComplexKeyParamsField      = "Params"
	ComplexKeyParams           = "$params"
	FinderNameParam            = "q"

	RootPackage         = "github.com/PapaCharlie/go-restli/v2"
	HashPackage         = RootPackage + "/fnv1a"
	RestLiPackage       = RootPackage + "/restli"
	RestLiPatchPackage  = RestLiPackage + "/patch"
	RestLiCodecPackage  = RootPackage + "/restlicodec"
	RestLiDataPackage   = RootPackage + "/restlidata"
	RestLiCommonPackage = RestLiDataPackage + "/generated/com/linkedin/restli/common"
	BatchKeySetPackage  = RestLiPackage + "/batchkeyset"
	EqualsPackage       = RestLiPackage + "/equals"
)

Variables

View Source
var (
	DoNotEditHeader = `Code generated by "github.com/PapaCharlie/go-restli/v2"; DO NOT EDIT.`
	// HeaderTemplate is a template for the header of generated files. According to golang.org/s/generatedcode,
	// generated files must have a specific header syntax.
	HeaderTemplate = template.Must(template.New("header").Parse(DoNotEditHeader + `

Source file: {{.SourceFile}}`))
)
View Source
var (
	NewJsonReader     = Code(Qual(RestLiCodecPackage, "NewJsonReader"))
	NewRequiredFields = Code(Qual(RestLiCodecPackage, "NewRequiredFields"))

	WriteCustomTyperef = Code(Qual(RestLiCodecPackage, "WriteCustomTyperef"))
	ReadCustomTyperef  = Code(Qual(RestLiCodecPackage, "ReadCustomTyperef"))

	BatchKeySet = Code(Id("set"))

	Hash     = Code(Qual(HashPackage, "Hash"))
	NewHash  = Code(Qual(HashPackage, "NewHash").Call())
	ZeroHash = Code(Qual(HashPackage, "ZeroHash").Call())

	IllegalEnumConstant = Code(Qual(RestLiPackage, "IllegalEnumConstant"))
	UnknownEnumValue    = Code(Qual(RestLiPackage, "UnknownEnumValue"))

	MultiLineCall = Options{
		Open:      "(",
		Close:     ")",
		Separator: ",",
		Multi:     true,
	}
	MultiLineValues = Options{
		Open:      "{",
		Close:     "}",
		Separator: ",",
		Multi:     true,
	}
)
View Source
var EmptyRecordIdentifier = Identifier{
	Name:      "EmptyRecord",
	Namespace: "com.linkedin.restli.common",
}
View Source
var PagingContextIdentifier = Identifier{
	Name:      "PagingContext",
	Namespace: "restlidata",
}
View Source
var RawRecordIdentifier = Identifier{
	Name:      "RawRecord",
	Namespace: "restlidata",
}
View Source
var TypeRegistry = &typeRegistry{
	types:        map[Identifier]*registeredType{},
	packageRoots: map[string]IdentifierSet{},
}

Functions

func AddFuncOnReceiver

func AddFuncOnReceiver(def *Statement, receiver, typeName, funcName string, pointer ShouldUsePointer) *Statement

func AddImportNames

func AddImportNames(f *File)

func AddPointer

func AddPointer(def *Statement, receiver, typeName string) *Statement

func AddStringer

func AddStringer(def *Statement, receiver, typeName string, pointer ShouldUsePointer, f func(def *Group)) *Statement

func AddWordWrappedComment

func AddWordWrappedComment(code *Statement, comment string) *Statement

func CleanTargetDir

func CleanTargetDir(targetDir string) (err error)

func ExportedIdentifier

func ExportedIdentifier(identifier string) string

func FqcpToPackagePath

func FqcpToPackagePath(packageRoot string, fqcp string) string

func IfErrReturn

func IfErrReturn(results ...Code) *Statement

func JsonFieldTag

func JsonFieldTag(name string, optional bool) map[string]string

func OrderedValues

func OrderedValues(f func(add func(key, value Code))) *Statement

func PackageName

func PackageName(pkg string) string

func ReceiverName

func ReceiverName(typeName string) string

func WriteJenFile

func WriteJenFile(filename string, file *File) error

Types

type CodeFile

type CodeFile struct {
	SourceFile  string
	PackagePath string
	PackageRoot string
	Filename    string
	Code        *Statement
}

func (*CodeFile) Write

func (f *CodeFile) Write(outputDir string) (err error)

type ComplexType

type ComplexType interface {
	GetIdentifier() Identifier
	GetSourceFile() string
	ReferencedTypes() IdentifierSet
	ShouldReference() ShouldUsePointer
	GenerateCode() *jen.Statement
}

type Identifier

type Identifier struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

func (Identifier) FullName

func (i Identifier) FullName() string

func (Identifier) GetIdentifier

func (i Identifier) GetIdentifier() Identifier

func (Identifier) IsCustomTyperef

func (i Identifier) IsCustomTyperef() bool

func (Identifier) IsEmptyRecord added in v2.1.1

func (i Identifier) IsEmptyRecord() bool

func (Identifier) PackagePath

func (i Identifier) PackagePath() string

func (Identifier) PackageRoot

func (i Identifier) PackageRoot() string

func (Identifier) Qual

func (i Identifier) Qual() *jen.Statement

func (Identifier) Receiver

func (i Identifier) Receiver() string

func (Identifier) Resolve

func (i Identifier) Resolve() ComplexType

func (Identifier) TypeName

func (i Identifier) TypeName() string

type IdentifierSet

type IdentifierSet map[Identifier]bool

func NewIdentifierSet

func NewIdentifierSet(ids ...Identifier) (set IdentifierSet)

func (IdentifierSet) Add

func (set IdentifierSet) Add(id Identifier)

func (IdentifierSet) AddAll

func (set IdentifierSet) AddAll(other IdentifierSet)

func (IdentifierSet) Range

func (set IdentifierSet) Range(f func(id Identifier))

func (IdentifierSet) Remove

func (set IdentifierSet) Remove(id Identifier)

func (IdentifierSet) String

func (set IdentifierSet) String() string

type Path

type Path []Identifier

func (Path) Add

func (p Path) Add(id Identifier) Path

func (Path) IntroducesCycle

func (p Path) IntroducesCycle(nextNode Identifier) Path

func (Path) SeenNode

func (p Path) SeenNode(id Identifier) bool

type ShouldUsePointer

type ShouldUsePointer int

func (ShouldUsePointer) ShouldUsePointer

func (p ShouldUsePointer) ShouldUsePointer() bool

Jump to

Keyboard shortcuts

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