Help us shape the future of Go! Take the 2026 Go Developer Survey

sample

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package sample provides a Connect service for ingress experiments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert added in v0.19.0

type Alert struct {
	ID       string `json:"id,omitempty"`
	Severity string `json:"severity,omitempty"`
	Headline string `json:"headline,omitempty"`
}

Alert describes an active weather warning.

type DailyForecast added in v0.19.0

type DailyForecast struct {
	Date                 string              `json:"date,omitempty"`
	High                 Option[Temperature] `json:"high,omitzero"`
	Low                  Option[Temperature] `json:"low,omitzero"`
	PrecipitationPercent int32               `json:"precipitation_percent,omitempty"`
	Wind                 Option[Wind]        `json:"wind,omitzero"`
}

DailyForecast holds the weather expected on one date.

type FetchForecastResponse added in v0.19.0

type FetchForecastResponse struct {
	Forecast Option[Forecast] `json:"forecast,omitzero"`
	Message  Option[string]   `json:"message,omitzero"`
}

FetchForecastResponse holds a provider forecast or an error message.

func (*FetchForecastResponse) UnmarshalJSON added in v0.23.1

func (r *FetchForecastResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects unknown fields; see decodeStrict.

type Forecast added in v0.19.0

type Forecast struct {
	Location string          `json:"location,omitempty"`
	Days     []DailyForecast `json:"days,omitempty"`
}

Forecast holds a location's daily forecasts.

func (*Forecast) UnmarshalJSON added in v0.23.1

func (f *Forecast) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects unknown fields; see decodeStrict.

type ForecastClient added in v0.16.0

type ForecastClient struct {
	// contains filtered or unexported fields
}

ForecastClient fetches forecasts from a ForecastProvider, usually through egress. It sends the provider's host name so egress can select the destination.

func NewForecastClient added in v0.16.0

func NewForecastClient(target *url.URL, host string, transport http.RoundTripper) *ForecastClient

NewForecastClient sends requests for host to target through transport.

func (*ForecastClient) Fetch added in v0.16.0

func (c *ForecastClient) Fetch(ctx context.Context, location string) (forecast Option[Forecast], status int)

Fetch returns the forecast for a location, or the status to report instead. A provider failure other than an unknown location is reported as a bad gateway.

type ForecastProvider added in v0.16.0

type ForecastProvider struct {
	// contains filtered or unexported fields
}

ForecastProvider serves the raw HTTP JSON forecast API that the weather sample calls in dependency mode.

func NewForecastProvider added in v0.16.0

func NewForecastProvider(data []byte) (*ForecastProvider, error)

NewForecastProvider loads forecasts from the same data format as NewWeather, ignoring alerts.

func (*ForecastProvider) FetchForecast added in v0.16.0

func (p *ForecastProvider) FetchForecast(writer http.ResponseWriter, request *http.Request)

FetchForecast serves GET /v1/forecasts/{location}.

type GetForecastResponse added in v0.19.0

type GetForecastResponse struct {
	Forecast Option[Forecast] `json:"forecast,omitzero"`
	Success  Option[bool]     `json:"success,omitzero"`
	Message  Option[string]   `json:"message,omitzero"`
}

GetForecastResponse holds a forecast or an error.

type GetForecastV2Response added in v0.19.0

type GetForecastV2Response struct {
	Forecast Option[Forecast] `json:"forecast,omitzero"`
	Alerts   []Alert          `json:"alerts,omitempty"`
	Success  Option[bool]     `json:"success,omitzero"`
	Message  Option[string]   `json:"message,omitzero"`
}

GetForecastV2Response adds the location's active alerts, in no particular order.

func (*GetForecastV2Response) UnmarshalJSON added in v0.23.1

func (r *GetForecastV2Response) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects unknown fields; see decodeStrict.

type GetStatusResponse added in v0.19.0

type GetStatusResponse struct {
	Status   string         `json:"status,omitempty"`
	Revision string         `json:"revision,omitempty"`
	Message  Option[string] `json:"message,omitzero"`
}

GetStatusResponse reports the service status and revision.

type Server added in v0.3.0

type Server struct {
	// contains filtered or unexported fields
}

Server serves sample Connect requests and HTTP health checks on one listener.

func NewServer added in v0.3.0

func NewServer(connectHandler http.Handler) *Server

NewServer constructs a sample server around a configured Connect handler.

func (*Server) Serve added in v0.3.0

func (s *Server) Serve(ctx context.Context, listener net.Listener) error

Serve accepts sample traffic until the context is cancelled or the server fails.

func (*Server) ServeHTTP added in v0.3.0

func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP serves sample Connect requests and health checks.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service serves a read-only snapshot loaded from ProtoJSON.

func New

func New(data []byte) (*Service, error)

New loads sample users from a ProtoJSON ListUsersResponse.

func (*Service) GetUser

GetUser returns one sample user, or InvalidArgument or NotFound for an invalid ID.

func (*Service) ListUsers

ListUsers filters by IDs and optional role, preserving fixture order.

type Temperature added in v0.19.0

type Temperature struct {
	Degrees float64 `json:"degrees,omitempty"`
	Unit    string  `json:"unit,omitempty"`
}

Temperature holds a measurement and its unit.

func (*Temperature) UnmarshalJSON added in v0.23.1

func (t *Temperature) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects unknown fields; see decodeStrict.

type Weather added in v0.12.0

type Weather struct {
	// contains filtered or unexported fields
}

Weather serves raw HTTP JSON endpoints modelled on a legacy weather service.

func NewWeather added in v0.12.0

func NewWeather(data []byte, revision string, forecasts Option[*ForecastClient]) (*Weather, error)

NewWeather loads weather from a JSON object mapping locations to GetForecastV2Response values. A forecasts client enables dependency mode.

func (*Weather) GetForecast added in v0.12.0

func (w *Weather) GetForecast(writer http.ResponseWriter, request *http.Request)

GetForecast serves GET /api/v1/forecast for a location.

func (*Weather) GetForecastV2 added in v0.12.0

func (w *Weather) GetForecastV2(writer http.ResponseWriter, request *http.Request)

GetForecastV2 serves GET /v2/forecast for a location, including its alerts.

func (*Weather) GetStatus added in v0.12.0

func (w *Weather) GetStatus(writer http.ResponseWriter, _ *http.Request)

GetStatus serves GET /_status.

type Wind added in v0.19.0

type Wind struct {
	SpeedKph  float64 `json:"speed_kph,omitempty"`
	Direction string  `json:"direction,omitempty"`
}

Wind holds its speed and direction.

func (*Wind) UnmarshalJSON added in v0.23.1

func (w *Wind) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects unknown fields; see decodeStrict.

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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