Documentation
¶
Overview ¶
Package service provides functionality to determine the service and entry paths for a struct.
Example ¶
package main
import (
"fmt"
"net/url"
"github.com/splunk/go-splunk-client/pkg/service"
)
// Title is a string that uniquely identifies a resource.
type Title string
// GetServicePath implements custom GetServicePath encoding. It returns the given
// path back, which has the effect of using the Title field's struct tag as
// its GetServicePath.
func (t Title) GetServicePath(path string) (string, error) {
return path, nil
}
// GetEntryPath implements custom GetEntryPath encoding. It returns the url-encoded
// value of the Title with the given path preceding it.
func (t Title) GetEntryPath(path string) (string, error) {
servicePath, err := t.GetServicePath(path)
if err != nil {
return "", err
}
return fmt.Sprintf("%s/%s", servicePath, url.PathEscape(string(t))), nil
}
// Artist represents a musical artist.
type Artist struct {
// Name is a Title which determines both the ServicePath (music/artists)
// and EntryPath (music/artists/<Title>).
Name Title `service:"music/artists"`
}
func main() {
newArtist := Artist{Name: "The Refreshments"}
servicePath, _ := service.ServicePath(newArtist)
fmt.Printf("path to create Artist: %s\n", servicePath)
entryPath, _ := service.EntryPath(newArtist)
fmt.Printf("path to existing Artist: %s\n", entryPath)
}
Output: path to create Artist: music/artists path to existing Artist: music/artists/The%20Refreshments
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EntryPath ¶
EntryPath returns the relative entry path for an object.
The path will be the first of these that are present:
• The value returned by the struct's EntryPath method, if implemented.
• The value returned by an exported service.EntryPathGetter member field's EntryPath method, which will be passed that field's "service" tag value.
func ServicePath ¶
ServicePath returns the relative service path for an object.
The path will be the first of these that are present:
• The value returned by the struct's GetServicePath method, if the struct is a service.ServicePathGetter.
• The value returned by an exported field's GetServicePath method, if the struct is a service.ServicePathGetter. The field's "service" tag will be passed to its GetServicePath method..
Types ¶
type EntryPathGetter ¶
type EntryPathGetter interface {
// GetEntryPath returns the object's entry path based on the provided value.
GetEntryPath(string) (string, error)
}
EntryPathGetter is the interfacae for types that implement GetEntryPath.
type ServicePathGetter ¶
type ServicePathGetter interface {
// GetServicePath returns the object's service path based on the provided value.
GetServicePath(string) (string, error)
}
ServicePathGetter is the interface for types that implement GetServicePath.
type StatusCodes ¶
StatusCodes define the expected status code returned for a given operation.
func ServiceStatusCodes ¶
func ServiceStatusCodes(input interface{}, defaults StatusCodes) (StatusCodes, error)
ServiceStatusCodes returns the StatusCodes configuration for the given input struct.
func (StatusCodes) WithDefaults ¶
func (codes StatusCodes) WithDefaults(defaults StatusCodes) StatusCodes
WithDefaults returns a new StatusCodes with values from defaults applied for any field with the zero value.
func (StatusCodes) WithTagDefaults ¶
func (codes StatusCodes) WithTagDefaults(tag string, defaults StatusCodes) (StatusCodes, error)
WithTagDefaults returns a new StatusCodes by applying the given tag and defaults.
type TagDefaultsStatusCoder ¶
type TagDefaultsStatusCoder interface {
WithTagDefaults(string, StatusCodes) (StatusCodes, error)
}
TagDefaultsStatusCoder is the interface for types that return a StatusCodes object from a service tag configuration and default StatusCodes value.