Documentation ¶
Index ¶
- Constants
- Variables
- func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error
- func ParseName(segment string) string
- func ParseUrlPath(path string) (*GoDataSegment, *GoDataSegment, error)
- func SemanticizeExpandQuery(expand *GoDataExpandQuery, service *GoDataService, entity *GoDataEntityType) error
- func SemanticizeFilterQuery(filter *GoDataFilterQuery, service *GoDataService, entity *GoDataEntityType) error
- func SemanticizeOrderByQuery(orderby *GoDataOrderByQuery, service *GoDataService, entity *GoDataEntityType) error
- func SemanticizePathSegment(segment *GoDataSegment, service *GoDataService) error
- func SemanticizeRequest(req *GoDataRequest, service *GoDataService) error
- func SemanticizeSelectQuery(sel *GoDataSelectQuery, service *GoDataService, entity *GoDataEntityType) error
- type ExpandItem
- type Function
- type GoDataAction
- type GoDataActionImport
- type GoDataAnnotation
- type GoDataAnnotations
- type GoDataApplyQuery
- type GoDataComplexType
- type GoDataCountQuery
- type GoDataEntityContainer
- type GoDataEntitySet
- type GoDataEntityType
- type GoDataEnumType
- type GoDataError
- func BadRequestError(message string) *GoDataError
- func GoneError(message string) *GoDataError
- func InternalServerError(message string) *GoDataError
- func MethodNotAllowedError(message string) *GoDataError
- func NotFoundError(message string) *GoDataError
- func NotImplementedError(message string) *GoDataError
- func PreconditionFailedError(message string) *GoDataError
- type GoDataExpandQuery
- type GoDataFilterQuery
- type GoDataFormatQuery
- type GoDataFunction
- type GoDataFunctionImport
- type GoDataIdentifier
- type GoDataInclude
- type GoDataIncludeAnnotations
- type GoDataInlineCountQuery
- type GoDataKey
- type GoDataMember
- type GoDataMetadata
- type GoDataNavigationProperty
- type GoDataNavigationPropertyBinding
- type GoDataOnDelete
- type GoDataOrderByQuery
- type GoDataParameter
- type GoDataProperty
- type GoDataPropertyRef
- type GoDataProvider
- type GoDataQuery
- type GoDataReference
- type GoDataReferentialConstraint
- type GoDataRequest
- type GoDataResponse
- type GoDataResponseField
- type GoDataReturnType
- type GoDataSchema
- type GoDataSearchQuery
- type GoDataSegment
- type GoDataSelectQuery
- type GoDataService
- func (service *GoDataService) GoDataHTTPHandler(w http.ResponseWriter, r *http.Request)
- func (service *GoDataService) ListenAndServe(addr string)
- func (service *GoDataService) LookupEntitySet(name string) (*GoDataEntitySet, error)
- func (service *GoDataService) LookupEntityType(name string) (*GoDataEntityType, error)
- type GoDataServices
- type GoDataSingleton
- type GoDataSkipQuery
- type GoDataTerm
- type GoDataTopQuery
- type GoDataTypeDefinition
- type Operator
- type OrderByItem
- type ParseNode
- type Parser
- type SelectItem
- type Token
- type TokenMatcher
- type Tokenizer
Constants ¶
const ( ExpandTokenOpenParen = iota ExpandTokenCloseParen ExpandTokenComma ExpandTokenSemicolon ExpandTokenEquals ExpandTokenLiteral )
const ( FilterTokenOpenParen int = iota FilterTokenCloseParen FilterTokenWhitespace FilterTokenColon // for 'any' and 'all' lambda operators FilterTokenComma FilterTokenLogical FilterTokenOp FilterTokenFunc FilterTokenLambda FilterTokenNull FilterTokenIt FilterTokenRoot FilterTokenFloat FilterTokenInteger FilterTokenString FilterTokenDate FilterTokenTime FilterTokenDateTime FilterTokenBoolean FilterTokenLiteral )
const ( ALLPAGES = "allpages" NONE = "none" )
const ( GoDataString = "Edm.String" GoDataInt16 = "Edm.Int16" GoDataInt32 = "Edm.Int32" GoDataInt64 = "Edm.Int64" GoDataDecimal = "Edm.Decimal" GoDataBinary = "Edm.Binary" GoDataBoolean = "Edm.Boolean" GoDataTimeOfDay = "Edm.TimeOfDay" GoDataDate = "Edm.Date" GoDataDateTimeOffset = "Edm.DateTimeOffset" )
const ( ASC = "asc" DESC = "desc" )
const ( OpAssociationLeft int = iota OpAssociationRight OpAssociationNone )
const ( NodeTypeLiteral int = iota NodeTypeOp NodeTypeFunc )
const ( RequestKindUnknown int = iota RequestKindMetadata RequestKindService RequestKindEntity RequestKindCollection RequestKindSingleton RequestKindProperty RequestKindPropertyValue RequestKindRef RequestKindCount )
const ( SemanticTypeUnknown int = iota SemanticTypeEntity SemanticTypeEntitySet SemanticTypeDerivedEntity SemanticTypeAction SemanticTypeFunction SemanticTypeProperty SemanticTypePropertyValue SemanticTypeRef SemanticTypeCount SemanticTypeMetadata )
const ( SearchTokenLiteral int = iota SearchTokenOpenParen SearchTokenCloseParen SearchTokenOp SearchTokenWhitespace )
const ( ODataFieldContext string = "@odata.context" ODataFieldCount string = "@odata.count" ODataFieldValue string = "value" )
Variables ¶
var GlobalExpandTokenizer = ExpandTokenizer()
var GlobalFilterParser = FilterParser()
var GlobalFilterTokenizer = FilterTokenizer()
var GlobalSearchParser = SearchParser()
var GlobalSearchTokenizer = SearchTokenizer()
Functions ¶
func ParseExpandOption ¶
func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error
func ParseUrlPath ¶
func ParseUrlPath(path string) (*GoDataSegment, *GoDataSegment, error)
func SemanticizeExpandQuery ¶
func SemanticizeExpandQuery( expand *GoDataExpandQuery, service *GoDataService, entity *GoDataEntityType, ) error
func SemanticizeFilterQuery ¶
func SemanticizeFilterQuery( filter *GoDataFilterQuery, service *GoDataService, entity *GoDataEntityType, ) error
func SemanticizeOrderByQuery ¶
func SemanticizeOrderByQuery(orderby *GoDataOrderByQuery, service *GoDataService, entity *GoDataEntityType) error
func SemanticizePathSegment ¶
func SemanticizePathSegment(segment *GoDataSegment, service *GoDataService) error
func SemanticizeRequest ¶
func SemanticizeRequest(req *GoDataRequest, service *GoDataService) error
Compare a request to a given service, and validate the semantics and update the request with semantics included
func SemanticizeSelectQuery ¶
func SemanticizeSelectQuery(sel *GoDataSelectQuery, service *GoDataService, entity *GoDataEntityType) error
Types ¶
type ExpandItem ¶
type ExpandItem struct { Path []*Token Filter *GoDataFilterQuery Search *GoDataSearchQuery OrderBy *GoDataOrderByQuery Skip *GoDataSkipQuery Top *GoDataTopQuery Select *GoDataSelectQuery Expand *GoDataExpandQuery Levels int }
Represents an item to expand in an OData query. Tracks the path of the entity to expand and also the filter, levels, and reference options, etc.
func ParseExpandItem ¶
func ParseExpandItem(input tokenQueue) (*ExpandItem, error)
type GoDataAction ¶
type GoDataAction struct { XMLName xml.Name `xml:"Action"` Name string `xml:"Name,attr"` IsBound string `xml:"IsBound,attr,omitempty"` EntitySetPath string `xml:"EntitySetPath,attr,omitempty"` Parameters []*GoDataParameter ReturnType *GoDataReturnType }
type GoDataActionImport ¶
type GoDataAnnotation ¶
type GoDataAnnotations ¶
type GoDataAnnotations struct { XMLName xml.Name `xml:"Annotations"` Target string `xml:"Target,attr"` Qualifier string `xml:"Qualifier,attr,omitempty"` Annotations []*GoDataAnnotation }
type GoDataApplyQuery ¶
type GoDataApplyQuery string
func ParseApplyString ¶
func ParseApplyString(apply string) (*GoDataApplyQuery, error)
type GoDataComplexType ¶
type GoDataCountQuery ¶
type GoDataCountQuery bool
func ParseCountString ¶
func ParseCountString(count string) (*GoDataCountQuery, error)
type GoDataEntityContainer ¶
type GoDataEntityContainer struct { XMLName xml.Name `xml:"EntityContainer"` Name string `xml:"Name,attr"` Extends string `xml:"Extends,attr,omitempty"` EntitySets []*GoDataEntitySet Singletons []*GoDataSingleton ActionImports []*GoDataActionImport FunctionImports []*GoDataFunctionImport }
type GoDataEntitySet ¶
type GoDataEntityType ¶
type GoDataEntityType struct { XMLName xml.Name `xml:"EntityType"` Name string `xml:"Name,attr"` BaseType string `xml:"BaseType,attr,omitempty"` Abstract string `xml:"Abstract,attr,omitempty"` OpenType string `xml:"OpenType,attr,omitempty"` HasStream string `xml:"HasStream,attr,omitempty"` Key *GoDataKey Properties []*GoDataProperty }
type GoDataEnumType ¶
type GoDataError ¶
func BadRequestError ¶
func BadRequestError(message string) *GoDataError
func GoneError ¶
func GoneError(message string) *GoDataError
func InternalServerError ¶
func InternalServerError(message string) *GoDataError
func MethodNotAllowedError ¶
func MethodNotAllowedError(message string) *GoDataError
func NotFoundError ¶
func NotFoundError(message string) *GoDataError
func NotImplementedError ¶
func NotImplementedError(message string) *GoDataError
func PreconditionFailedError ¶
func PreconditionFailedError(message string) *GoDataError
func (*GoDataError) Error ¶
func (err *GoDataError) Error() string
type GoDataExpandQuery ¶
type GoDataExpandQuery struct {
ExpandItems []*ExpandItem
}
func ParseExpandString ¶
func ParseExpandString(expand string) (*GoDataExpandQuery, error)
type GoDataFilterQuery ¶
type GoDataFilterQuery struct {
Tree *ParseNode
}
Stores a parsed version of the filter query string. Can be used by providers to apply the filter based on their own implementation. The filter is stored as a parse tree that can be traversed.
func ParseFilterString ¶
func ParseFilterString(filter string) (*GoDataFilterQuery, error)
Convert an input string from the $filter part of the URL into a parse tree that can be used by providers to create a response.
type GoDataFormatQuery ¶
type GoDataFormatQuery struct { }
type GoDataFunction ¶
type GoDataFunction struct { XMLName xml.Name `xml:"Function"` Name string `xml:"Name,attr"` IsBound string `xml:"IsBound,attr,omitempty"` IsComposable string `xml:"IsComposable,attr,omitempty"` EntitySetPath string `xml:"EntitySetPath,attr,omitempty"` Parameters []*GoDataParameter ReturnType *GoDataReturnType }
type GoDataFunctionImport ¶
type GoDataIdentifier ¶
func ParseIdentifiers ¶
func ParseIdentifiers(segment string) *GoDataIdentifier
func (*GoDataIdentifier) Get ¶
func (id *GoDataIdentifier) Get() string
Return the first key in the map. This is how you should get the identifier for single values, e.g. when the path is Employee(1), etc.
func (*GoDataIdentifier) GetKey ¶
func (id *GoDataIdentifier) GetKey(key string) (string, bool)
Return a specific value for a specific key.
func (*GoDataIdentifier) HasMultiple ¶
func (id *GoDataIdentifier) HasMultiple() bool
Check if this identifier has more than one key/value pair.
type GoDataInclude ¶
type GoDataInlineCountQuery ¶
type GoDataInlineCountQuery string
func ParseInlineCountString ¶
func ParseInlineCountString(inlinecount string) (*GoDataInlineCountQuery, error)
type GoDataKey ¶
type GoDataKey struct { XMLName xml.Name `xml:"Key"` PropertyRef *GoDataPropertyRef }
type GoDataMember ¶
type GoDataMetadata ¶
type GoDataMetadata struct { XMLName xml.Name `xml:"edmx:Edmx"` XMLNamespace string `xml:"xmlns:edmx,attr"` Version string `xml:"Version,attr"` DataServices *GoDataServices References []*GoDataReference }
func (*GoDataMetadata) Bytes ¶
func (t *GoDataMetadata) Bytes() ([]byte, error)
type GoDataNavigationProperty ¶
type GoDataNavigationProperty struct {}
type GoDataNavigationPropertyBinding ¶
type GoDataNavigationPropertyBinding struct {}
type GoDataOnDelete ¶
type GoDataOrderByQuery ¶
type GoDataOrderByQuery struct {
OrderByItems []*OrderByItem
}
func ParseOrderByString ¶
func ParseOrderByString(orderby string) (*GoDataOrderByQuery, error)
type GoDataParameter ¶
type GoDataParameter struct { XMLName xml.Name `xml:"Parameter"` Name string `xml:"Name,attr"` Type string `xml:"Type,attr"` Nullable string `xml:"Nullable,attr,omitempty"` MaxLength int `xml:"MaxLength,attr,omitempty"` Precision int `xml:"Precision,attr,omitempty"` Scale int `xml:"Scale,attr,omitempty"` SRID string `xml:"SRID,attr,omitempty"` }
type GoDataProperty ¶
type GoDataProperty struct { XMLName xml.Name `xml:"Property"` Name string `xml:"Name,attr"` Type string `xml:"Type,attr"` Nullable string `xml:"Nullable,attr,omitempty"` MaxLength int `xml:"MaxLength,attr,omitempty"` Precision int `xml:"Precision, attr,omitempty"` Scale int `xml:"Scale,attr,omitempty"` Unicode string `xml:"Unicode,attr,omitempty"` SRID string `xml:"SRID,attr,omitempty"` DefaultValue string `xml:"DefaultValue,attr,omitempty"` }
type GoDataPropertyRef ¶
type GoDataProvider ¶
type GoDataProvider interface { // Request a single entity from the provider. Should return a response field // that contains the value mapping properties to values for the entity. GetEntity(*GoDataRequest) (*GoDataResponseField, error) // Request a collection of entities from the provider. Should return a // response field that contains the value of a slice of every entity in the // collection filtered by the request query parameters. GetEntityCollection(*GoDataRequest) (*GoDataResponseField, error) // Request the number of entities in a collection, disregarding any filter // query parameters. GetCount(*GoDataRequest) (int, error) // Get the object model representation from the provider. GetMetadata() *GoDataMetadata }
The basic interface for a GoData provider. All providers must implement these functions.
type GoDataQuery ¶
type GoDataQuery struct { Filter *GoDataFilterQuery Apply *GoDataApplyQuery Expand *GoDataExpandQuery Select *GoDataSelectQuery OrderBy *GoDataOrderByQuery Top *GoDataTopQuery Skip *GoDataSkipQuery Count *GoDataCountQuery InlineCount *GoDataInlineCountQuery Search *GoDataSearchQuery Format *GoDataFormatQuery }
func ParseUrlQuery ¶
func ParseUrlQuery(query url.Values) (*GoDataQuery, error)
type GoDataReference ¶
type GoDataReference struct { XMLName xml.Name `xml:"edmx:Reference"` Uri string `xml:"Uri,attr"` Includes []*GoDataInclude IncludeAnnotations []*GoDataIncludeAnnotations }
type GoDataReferentialConstraint ¶
type GoDataReferentialConstraint struct { XMLName xml.Name `xml:"ReferentialConstraint"` Property string `xml:"Property,attr"` ReferencedProperty string `xml:"ReferencedProperty,attr"` OnDelete *GoDataOnDelete `xml:"OnDelete,omitempty"` }
type GoDataRequest ¶
type GoDataRequest struct { FirstSegment *GoDataSegment LastSegment *GoDataSegment Query *GoDataQuery RequestKind int }
func ParseRequest ¶
func ParseRequest(path string, query url.Values) (*GoDataRequest, error)
Parse a request from the HTTP server and format it into a GoDaataRequest type to be passed to a provider to produce a result.
type GoDataResponse ¶
type GoDataResponse struct {
Fields map[string]*GoDataResponseField
}
A response is a dictionary of keys to their corresponding fields. This will be converted into a JSON dictionary in the response to the web client.
func (*GoDataResponse) Json ¶
func (r *GoDataResponse) Json() ([]byte, error)
Serialize the result as JSON for sending to the client. If an error occurs during the serialization, it will be returned.
type GoDataResponseField ¶
type GoDataResponseField struct {
Value interface{}
}
A response that is a primitive JSON type or a list or a dictionary. When writing to JSON, it is automatically mapped from the Go type to a suitable JSON data type. Any type can be used, but if the data type is not supported for serialization, then an error is thrown.
func (*GoDataResponseField) Json ¶
func (f *GoDataResponseField) Json() ([]byte, error)
Convert the response field to a JSON serialized form. If the type is not string, []byte, int, float64, map[string]*GoDataResponseField, or []*GoDataResponseField, then an error will be thrown.
type GoDataReturnType ¶
type GoDataReturnType struct { XMLName xml.Name `xml:"ReturnType"` Name string `xml:"Name,attr"` Type string `xml:"Type,attr"` Nullable string `xml:"Nullable,attr,omitempty"` MaxLength int `xml:"MaxLength,attr,omitempty"` Precision int `xml:"Precision,attr,omitempty"` Scale int `xml:"Scale,attr,omitempty"` SRID string `xml:"SRID,attr,omitempty"` }
type GoDataSchema ¶
type GoDataSchema struct { XMLName xml.Name `xml:"Schema"` Namespace string `xml:"Namespace,attr"` Alias string `xml:"Alias,attr,omitempty"` Actions []*GoDataAction Annotations []*GoDataAnnotations Annotation []*GoDataAnnotation ComplexTypes []*GoDataComplexType EntityContainers []*GoDataEntityContainer EntityTypes []*GoDataEntityType EnumTypes []*GoDataEnumType Functions []*GoDataFunction Terms []*GoDataTerm TypeDefinitions []*GoDataTypeDefinition }
type GoDataSearchQuery ¶
type GoDataSearchQuery struct {
Tree *ParseNode
}
func ParseSearchString ¶
func ParseSearchString(filter string) (*GoDataSearchQuery, error)
Convert an input string from the $filter part of the URL into a parse tree that can be used by providers to create a response.
type GoDataSegment ¶
type GoDataSegment struct { // The raw segment parsed from the URI RawValue string // The kind of resource being pointed at by this segment SemanticType int // A pointer to the metadata type this object represents, as defined by a // particular service SemanticReference interface{} // The name of the entity, type, collection, etc. Name string // map[string]string of identifiers passed to this segment. If the identifier // is not key/value pair(s), then all values will be nil. If there is no // identifier, it will be nil. Identifier *GoDataIdentifier // The next segment in the path. Next *GoDataSegment // The previous segment in the path. Prev *GoDataSegment }
Represents a segment (slash-separated) part of the URI path. Each segment has a link to the next segment (the last segment precedes nil).
type GoDataSelectQuery ¶
type GoDataSelectQuery struct {
SelectItems []*SelectItem
}
func ParseSelectString ¶
func ParseSelectString(sel string) (*GoDataSelectQuery, error)
type GoDataService ¶
type GoDataService struct { // The base url for the service. Navigating to this URL will display the // service document. BaseUrl *url.URL // The provider for this service that is serving the data to the OData API. Provider GoDataProvider // Metadata cache taken from the provider. Metadata *GoDataMetadata // A mapping from schema names to schema references SchemaLookup map[string]*GoDataSchema // A bottom-up mapping from entity type names to schema namespaces to // the entity type reference EntityTypeLookup map[string]map[string]*GoDataEntityType // A bottom-up mapping from entity container names to schema namespaces to // the entity container reference EntityContainerLookup map[string]map[string]*GoDataEntityContainer // A bottom-up mapping from entity set names to entity collection names to // schema namespaces to the entity set reference EntitySetLookup map[string]map[string]map[string]*GoDataEntitySet // A lookup for entity properties if an entity type is given, lookup // properties by name PropertyLookup map[*GoDataEntityType]map[string]*GoDataProperty // lookup navigational properties by name NavigationPropertyLookup map[*GoDataEntityType]map[string]*GoDataNavigationProperty }
A GoDataService will spawn an HTTP listener, which will connect GoData requests with a backend provider given to it.
func BuildService ¶
func BuildService(provider GoDataProvider, serviceUrl string) (*GoDataService, error)
Create a new service from a given provider. This step builds lookups for all parts of the data model, so constant time lookups can be performed. This step only happens once when the server starts up, so the overall cost is minimal. The given url will be treated as the base URL for all service requests, and used for building context URLs, etc.
func (*GoDataService) GoDataHTTPHandler ¶
func (service *GoDataService) GoDataHTTPHandler(w http.ResponseWriter, r *http.Request)
The default handler for parsing requests as GoDataRequests, passing them to a GoData provider, and then building a response.
func (*GoDataService) ListenAndServe ¶
func (service *GoDataService) ListenAndServe(addr string)
Start the service listening on the given address.
func (*GoDataService) LookupEntitySet ¶
func (service *GoDataService) LookupEntitySet(name string) (*GoDataEntitySet, error)
Lookup an entity set from the service metadata. Accepts a fully qualified name, e.g., ODataService.ContainerName.EntitySetName, ContainerName.EntitySetName or, if unambiguous, accepts a simple identifier, e.g., EntitySetName.
func (*GoDataService) LookupEntityType ¶
func (service *GoDataService) LookupEntityType(name string) (*GoDataEntityType, error)
Lookup an entity type from the service metadata. Accepts a fully qualified name, e.g., ODataService.EntityTypeName or, if unambiguous, accepts a simple identifier, e.g., EntityTypeName.
type GoDataServices ¶
type GoDataServices struct { XMLName xml.Name `xml:"edmx:DataServices"` Schemas []*GoDataSchema }
type GoDataSingleton ¶
type GoDataSkipQuery ¶
type GoDataSkipQuery int
func ParseSkipString ¶
func ParseSkipString(skip string) (*GoDataSkipQuery, error)
type GoDataTerm ¶
type GoDataTopQuery ¶
type GoDataTopQuery int
func ParseTopString ¶
func ParseTopString(top string) (*GoDataTopQuery, error)
type GoDataTypeDefinition ¶
type GoDataTypeDefinition struct { XMLName xml.Name `xml:"TypeDefinition"` Name string `xml:"Name,attr"` UnderlyingType string `xml:"UnderlyingTypeattr,omitempty"` Annotations []*GoDataAnnotation }
type OrderByItem ¶
type Parser ¶
type Parser struct { // Map from string inputs to operator types Operators map[string]*Operator // Map from string inputs to function types Functions map[string]*Function }
func EmptyParser ¶
func EmptyParser() *Parser
func FilterParser ¶
func FilterParser() *Parser
func SearchParser ¶
func SearchParser() *Parser
func (*Parser) DefineFunction ¶
Add a function to the language
func (*Parser) DefineOperator ¶
Add an operator to the language. Provide the token, a precedence, and whether the operator is left, right, or not associative.
func (*Parser) InfixToPostfix ¶
Parse the input string of tokens using the given definitions of operators and functions. (Everything else is assumed to be a literal.) Uses the Shunting-Yard algorithm.
func (*Parser) PostfixToTree ¶
Convert a Postfix token queue to a parse tree
type SelectItem ¶
type SelectItem struct {
Segments []*Token
}
type Tokenizer ¶
type Tokenizer struct { TokenMatchers []*TokenMatcher IgnoreMatchers []*TokenMatcher }
func ExpandTokenizer ¶
func ExpandTokenizer() *Tokenizer
func FilterTokenizer ¶
func FilterTokenizer() *Tokenizer
Create a tokenizer capable of tokenizing filter statements
func SearchTokenizer ¶
func SearchTokenizer() *Tokenizer
Create a tokenizer capable of tokenizing filter statements