commons

package
v0.0.0-...-4799e85 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReqBodySuffix is suffix name for request body object
	ReqBodySuffix = "ReqBody"

	// RespBodySuffix is suffix name for response body object
	RespBodySuffix = "RespBody"
)

Variables

This section is empty.

Functions

func AtoiOrPanic

func AtoiOrPanic(str string) int

AtoiOrPanic convert a string to int and panic if failed

func CheckDuplicatedTitleTypes

func CheckDuplicatedTitleTypes(apiDef *raml.APIDefinition) error

CheckDuplicatedTitleTypes checks that the API definition has duplicated types of the title case version of the types. title case = first letter become uppercase example of non duplicate:

  • One & Two
  • One & oNe = One & ONe -> N is uppercase

example of duplicate - One & one = One & One

func DenormalizePkgName

func DenormalizePkgName(name string) string

inverse of normalizePkgName

func DisplayNameToFuncName

func DisplayNameToFuncName(str string) string

func GenerateFile

func GenerateFile(data interface{}, tmplFile, tmplName, filename string, override bool) error

GenerateFile generates file from a template. if file already exist and override==false, file won't be regenerated funcMap = this parameter is used for passing go function to the template

func GetBasicType

func GetBasicType(t string) string

GetBasicType returns basic type of a basic or complex type

func HasJSONBody

func HasJSONBody(body *raml.Bodies) bool

HasJSONBody checks if this raml.Bodies has JSON body that need to be generated it's struct. rules:

  • not nil application/json
  • has properties or has tipe in JSON string

func IsArrayType

func IsArrayType(t string) bool

IsArrayType returns true if the given string is a RAML array

func IsBuiltinType

func IsBuiltinType(t interface{}) bool

IsBuiltinType returns true if the given type is builtin type

func IsJSONString

func IsJSONString(s string) bool

IsJSONString returns true if a string is a JSON string

func IsStrInArray

func IsStrInArray(arr []string, str string) bool

IsStrInArray check if a string `str` is part of array `arr`

func MapToSortedStrings

func MapToSortedStrings(m map[string]struct{}) []string

MapToSortedStrings returns sorted string arrays from a map

func NormalizeIdentifier

func NormalizeIdentifier(s string) string

NormalizeIdentifier change invalid character in identifier to `_`. Edge cases: - If started with invalid char, we prepend with `The_` - don't replace `.` if it means a library

func NormalizeIdentifierWithLib

func NormalizeIdentifierWithLib(s string, apiDef *raml.APIDefinition) string

func NormalizePkgName

func NormalizePkgName(name string) string

normalize package name because not all characters can be used as package name

func NormalizeURI

func NormalizeURI(URI string) string

NormalizeURI removes `{`, `}`, `/`, and space from an URI

func NormalizeURITitle

func NormalizeURITitle(URI string) string

NormalizeURITitle does NormalizeURI with first character in upper case

func ParamizingURI

func ParamizingURI(URI, sep string) string

ParamizingURI creates parameterized URI Input : raw string, ex : /users/{userId}/address/{addressId} Output : "/users/"+userId+"/address/"+addressId TODO : optimize with regex

func ParseDescription

func ParseDescription(desc string) []string

ParseDescription create string slice from an RAML description. each element is a description line

func SnackCaseServerMethodName

func SnackCaseServerMethodName(displayName, verb string, resource *raml.Resource) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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