sdk

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sdk provides API handlers for [the endpoints provided by ld-relay](https://github.com/launchdarkly/ld-relay/blob/v8/docs/endpoints.md).

Not all routes are supported because some routes are for exclusively for SDKs that have reached end of life.

✅	/all	GET	stream.	SSE stream for all data
✅	/bulk	POST	events.	Receives analytics events from SDKs
✅	/diagnostic	POST	events.	Receives diagnostic data from SDKs
❌ 	/flags	GET	stream.	SSE stream for flag data (older SDKs)
✅ 	/sdk/flags	GET	sdk.	Polling endpoint for PHP SDK
✅ 	/sdk/flags/{flagKey}	GET	sdk.	Polling endpoint for PHP SDK
✅	/sdk/segments/{segmentKey}	GET	sdk.	Polling endpoint for PHP SDK (Segments are not used in dev server, so this always 404s)
✅	/meval/{contextBase64}	GET	clientstream.	SSE stream of "ping" and other events
✅	/meval	REPORT	clientstream.	Same as above, but request body is the evaluation context JSON object (not in base64)
✅	/mobile	POST	events.	For receiving events from mobile SDKs
✅	/mobile/events	POST	events.	Same as above
✅	/mobile/events/bulk	POST	events.	Same as above
✅	/mobile/events/diagnostic	POST	events.	Same as above
❌ 	/mping	GET	clientstream.	SSE stream for older SDKs that issues "ping" events when flags have changed
✅	/msdk/evalx/contexts/{contextBase64}	GET	clientsdk.	Polling endpoint, returns flag evaluation results for an evaluation context
✅	/msdk/evalx/context	REPORT	clientsdk.	Same as above but request body is the evaluation context JSON object (not in base64)
✅	/msdk/evalx/users/{contextBase64}	GET	clientsdk.	Alternate name for /msdk/evalx/contexts/{contextBase64} used by older SDKs
✅	/msdk/evalx/user	REPORT	clientsdk.	Alternate name for /msdk/evalx/context used by older SDKs
❌ 	/a/{envId}.gif?d=*events*	GET	events.	Alternative analytics event mechanism used if browser does not allow CORS
✅	/eval/{envId}/{contextBase64}	GET	clientstream.	SSE stream of "ping" and other events for JS and other client-side SDK listeners
✅	/eval/{envId}	REPORT	clientstream.	Same as above but request body is the evaluation context JSON object (not in base64)
✅	/events/bulk/{envId}	POST	events.	Receives analytics events from SDKs
✅	/events/diagnostic/{envId}	POST	events.	Receives diagnostic data from SDKs
❌ 	/ping/{envId}	GET	clientstream.	SSE stream for older SDKs that issues "ping" events when flags have changed
✅	/sdk/evalx/{envId}/contexts/{contextBase64}	GET	clientsdk.	Polling endpoint, returns flag evaluation results and additional metadata
✅	/sdk/evalx/{envId}/contexts	REPORT	clientsdk.	Same as above but request body is the evaluation context JSON object (not in base64)
✅	/sdk/evalx/{envId}/users/{contextBase64}	GET	clientsdk.	Alternate name for /sdk/evalx/{envId}/contexts/{contextBase64} used by older SDKs
✅	/sdk/evalx/{envId}/users	REPORT	clientsdk.	Alternate name for /sdk/evalx/{envId}/contexts used by older SDKs
✅	/sdk/goals/{envId}	GET	clientsdk.	Provides goals data used by JS SDK

Index

Constants

This section is empty.

Variables

View Source
var CorsHeaders = handlers.CORS(
	handlers.AllowedOrigins([]string{"*"}),
	handlers.AllowedMethods([]string{"GET"}),
	handlers.AllowCredentials(),
	handlers.ExposedHeaders([]string{"Date"}),
	handlers.AllowedHeaders([]string{"Cache-Control", "Content-Type", "Content-Length", "Accept-Encoding", "X-LaunchDarkly-Event-Schema", "X-LaunchDarkly-User-Agent", "X-LaunchDarkly-Payload-ID", "X-LaunchDarkly-Wrapper", "X-LaunchDarkly-Tags"}),
	handlers.MaxAge(300),
)
View Source
var EventsCorsHeaders = handlers.CORS(
	handlers.AllowedOrigins([]string{"*"}),
	handlers.AllowedMethods([]string{"POST"}),
	handlers.AllowCredentials(),
	handlers.AllowedHeaders([]string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-LaunchDarkly-Event-Schema", "X-LaunchDarkly-User-Agent", "X-LaunchDarkly-Payload-ID", "X-LaunchDarkly-Wrapper", "X-LaunchDarkly-Tags"}),
	handlers.ExposedHeaders([]string{"Date"}),
	handlers.MaxAge(300),
)

Functions

func BindRoutes

func BindRoutes(router *mux.Router)

func ConstantResponseHandler

func ConstantResponseHandler(statusCode int, response string) http.HandlerFunc

func GetAllFlagsFromContext

func GetAllFlagsFromContext(ctx context.Context) (model.FlagsState, error)

func GetClientFlags

func GetClientFlags(w http.ResponseWriter, r *http.Request)

func GetProjectKeyFromAuthorizationHeader

func GetProjectKeyFromAuthorizationHeader(handler http.Handler) http.Handler

func GetProjectKeyFromContext

func GetProjectKeyFromContext(ctx context.Context) string

func GetProjectKeyFromEnvIdParameter

func GetProjectKeyFromEnvIdParameter(pathParameter string) func(handler http.Handler) http.Handler

func GetServerFlags

func GetServerFlags(w http.ResponseWriter, r *http.Request)

func LatestAll added in v1.10.0

func LatestAll(w http.ResponseWriter, r *http.Request)

func OpenStream

func OpenStream(w http.ResponseWriter, done <-chan struct{}, initialMessage Message) (chan<- Message, <-chan error)

OpenStream sends data to a response using the initial payload and subsequently via the returned write only channel

func SdkEventsReceiveHandler added in v1.18.0

func SdkEventsReceiveHandler(writer http.ResponseWriter, request *http.Request)

func SendMessage

func SendMessage(
	updateChan chan<- Message,
	msgType MessageType,
	data interface{},
) error

func SetProjectKeyOnContext

func SetProjectKeyOnContext(ctx context.Context, projectKey string) context.Context

func StreamClientFlags

func StreamClientFlags(w http.ResponseWriter, r *http.Request)

func StreamServerAllPayload

func StreamServerAllPayload(w http.ResponseWriter, r *http.Request)

func WriteError

func WriteError(ctx context.Context, w http.ResponseWriter, err error)

WriteError writes out a given error if it's known or panics if it isn't. Two assumptions it's making

  • a panic handling middleware is in use
  • This is in the context of flag delivery which has pretty consistent semantics for what's an error across handlers.

Types

type Message

type Message struct {
	Event MessageType
	Data  []byte
}

func (Message) ToPayload

func (m Message) ToPayload() []byte

type MessageType

type MessageType string
const (
	TYPE_PUT   MessageType = "put"
	TYPE_PATCH MessageType = "patch"
)

type SDKEventBase added in v1.18.0

type SDKEventBase struct {
	Kind string `json:"kind"`
}

type ServerAllPayload

type ServerAllPayload struct {
	Path string `json:"path"`
	Data data   `json:"data"`
}

func ServerAllPayloadFromFlagsState

func ServerAllPayloadFromFlagsState(state model.FlagsState) ServerAllPayload

type ServerFlag

type ServerFlag struct {
	Key                    string                 `json:"key"`
	On                     bool                   `json:"on"`
	Prerequisites          []string               `json:"prerequisites"` // this isn't the real model for this, but this will always be empty for us
	Targets                []string               `json:"targets"`       // this isn't the real model for this, but this will always be empty for us
	Rules                  []string               `json:"rules"`         // this isn't the real model for this, but this will always be empty for us
	Fallthrough            fallthroughRule        `json:"fallthrough"`
	OffVariation           int                    `json:"offVariation"`
	Variations             []ldvalue.Value        `json:"variations"`
	ClientSideAvailability clientSideAvailability `json:"clientSideAvailability"`
	ClientSide             bool                   `json:"clientSide"`
	Salt                   string                 `json:"salt"`
	TrackEvents            bool                   `json:"trackEvents"`
	TrackEventsFallthrough bool                   `json:"trackEventsFallthrough"`
	DebugEventsUntilDate   int                    `json:"debugEventsUntilDate"`
	Version                int                    `json:"version"`
	Deleted                bool                   `json:"deleted"`
}

type ServerFlags

type ServerFlags map[string]ServerFlag

func ServerFlagsFromFlagsState

func ServerFlagsFromFlagsState(flagsState model.FlagsState) ServerFlags

Jump to

Keyboard shortcuts

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