weather

package module
v0.0.0-...-a65048b Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 11 Imported by: 1

README

weather

This service provides a simplified way to retrieve weather information from different weather APIs. It handles both Canadian (via Environment Canada) and American (via NOAA) weather conditions & forecasts.

Proto Generation

Use protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative weather.proto to regenerate the .pb.go files.

Documentation

Index

Constants

View Source
const (
	WeatherService_GetCurrentReport_FullMethodName = "/faltung.nerves.weather.WeatherService/GetCurrentReport"
	WeatherService_GetForecast_FullMethodName      = "/faltung.nerves.weather.WeatherService/GetForecast"
)

Variables

View Source
var (
	WeatherIcon_name = map[int32]string{
		0:  "SUNNY",
		1:  "CLOUDY",
		2:  "PARTIALLY_CLOUDY",
		3:  "MOSTLY_CLOUDY",
		4:  "RAIN",
		5:  "CHANCE_OF_RAIN",
		6:  "SNOW",
		7:  "CHANCE_OF_SNOW",
		8:  "SNOW_SHOWERS",
		9:  "THUNDERSTORMS",
		10: "FOG",
	}
	WeatherIcon_value = map[string]int32{
		"SUNNY":            0,
		"CLOUDY":           1,
		"PARTIALLY_CLOUDY": 2,
		"MOSTLY_CLOUDY":    3,
		"RAIN":             4,
		"CHANCE_OF_RAIN":   5,
		"SNOW":             6,
		"CHANCE_OF_SNOW":   7,
		"SNOW_SHOWERS":     8,
		"THUNDERSTORMS":    9,
		"FOG":              10,
	}
)

Enum value maps for WeatherIcon.

View Source
var (
	// ErrLocationNotFound is returned if the supplied lat/lon value can't be found.
	ErrLocationNotFound = status.New(codes.NotFound, "location not found")
)
View Source
var File_weather_proto protoreflect.FileDescriptor
View Source
var WeatherService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "faltung.nerves.weather.WeatherService",
	HandlerType: (*WeatherServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "GetCurrentReport",
			Handler:    _WeatherService_GetCurrentReport_Handler,
		},
		{
			MethodName: "GetForecast",
			Handler:    _WeatherService_GetForecast_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "weather.proto",
}

WeatherService_ServiceDesc is the grpc.ServiceDesc for WeatherService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterWeatherServiceServer

func RegisterWeatherServiceServer(s grpc.ServiceRegistrar, srv WeatherServiceServer)

Types

type API

type API struct {
	UnsafeWeatherServiceServer
	// contains filtered or unexported fields
}

API is an implementation of the WeatherService server.

func NewAPI

func NewAPI(logger *zap.Logger) *API

NewAPI creates a new weather service server.

func (*API) GetCurrentReport

func (api *API) GetCurrentReport(ctx context.Context, req *GetCurrentReportRequest) (*GetCurrentReportResponse, error)

GetCurrentReport gets a weather report

func (*API) GetForecast

func (api *API) GetForecast(ctx context.Context, req *GetForecastRequest) (*GetForecastResponse, error)

GetForecast gets a weather forecast.

func (*API) RegisterStation

func (api *API) RegisterStation(s Station)

RegisterStation takes the supplied station and adds it to the queryable set.

type GeoSet

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

GeoSet is a collection that allows for values to be stored by their latitude and longitude; and allows for lookups to find the entry closest to the supplied latitude and longitude.

func NewGeoSet

func NewGeoSet() *GeoSet

NewGeoSet returns a new GeoSet

func (*GeoSet) Add

func (gs *GeoSet) Add(lat float64, lon float64, value interface{})

Add the supplied value to the location specified with the latitude and longitude (in degrees)

func (*GeoSet) Closest

func (gs *GeoSet) Closest(lat float64, lon float64) interface{}

Closest returns the entry in the set that is nearest to the supplied latitude and longitude (in degrees)

type GetCurrentReportRequest

type GetCurrentReportRequest struct {
	Latitude  float64 `protobuf:"fixed64,1,opt,name=latitude,proto3" json:"latitude,omitempty"`
	Longitude float64 `protobuf:"fixed64,2,opt,name=longitude,proto3" json:"longitude,omitempty"`
	// contains filtered or unexported fields
}

func (*GetCurrentReportRequest) Descriptor deprecated

func (*GetCurrentReportRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetCurrentReportRequest.ProtoReflect.Descriptor instead.

func (*GetCurrentReportRequest) GetLatitude

func (x *GetCurrentReportRequest) GetLatitude() float64

func (*GetCurrentReportRequest) GetLongitude

func (x *GetCurrentReportRequest) GetLongitude() float64

func (*GetCurrentReportRequest) ProtoMessage

func (*GetCurrentReportRequest) ProtoMessage()

func (*GetCurrentReportRequest) ProtoReflect

func (x *GetCurrentReportRequest) ProtoReflect() protoreflect.Message

func (*GetCurrentReportRequest) Reset

func (x *GetCurrentReportRequest) Reset()

func (*GetCurrentReportRequest) String

func (x *GetCurrentReportRequest) String() string

type GetCurrentReportResponse

type GetCurrentReportResponse struct {
	Report      *WeatherReport `protobuf:"bytes,1,opt,name=report,proto3" json:"report,omitempty"`
	StationName string         `protobuf:"bytes,2,opt,name=station_name,json=stationName,proto3" json:"station_name,omitempty"`
	// contains filtered or unexported fields
}

func (*GetCurrentReportResponse) Descriptor deprecated

func (*GetCurrentReportResponse) Descriptor() ([]byte, []int)

Deprecated: Use GetCurrentReportResponse.ProtoReflect.Descriptor instead.

func (*GetCurrentReportResponse) GetReport

func (x *GetCurrentReportResponse) GetReport() *WeatherReport

func (*GetCurrentReportResponse) GetStationName

func (x *GetCurrentReportResponse) GetStationName() string

func (*GetCurrentReportResponse) ProtoMessage

func (*GetCurrentReportResponse) ProtoMessage()

func (*GetCurrentReportResponse) ProtoReflect

func (x *GetCurrentReportResponse) ProtoReflect() protoreflect.Message

func (*GetCurrentReportResponse) Reset

func (x *GetCurrentReportResponse) Reset()

func (*GetCurrentReportResponse) String

func (x *GetCurrentReportResponse) String() string

type GetForecastRequest

type GetForecastRequest struct {
	Latitude  float64 `protobuf:"fixed64,1,opt,name=latitude,proto3" json:"latitude,omitempty"`
	Longitude float64 `protobuf:"fixed64,2,opt,name=longitude,proto3" json:"longitude,omitempty"`
	// contains filtered or unexported fields
}

func (*GetForecastRequest) Descriptor deprecated

func (*GetForecastRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetForecastRequest.ProtoReflect.Descriptor instead.

func (*GetForecastRequest) GetLatitude

func (x *GetForecastRequest) GetLatitude() float64

func (*GetForecastRequest) GetLongitude

func (x *GetForecastRequest) GetLongitude() float64

func (*GetForecastRequest) ProtoMessage

func (*GetForecastRequest) ProtoMessage()

func (*GetForecastRequest) ProtoReflect

func (x *GetForecastRequest) ProtoReflect() protoreflect.Message

func (*GetForecastRequest) Reset

func (x *GetForecastRequest) Reset()

func (*GetForecastRequest) String

func (x *GetForecastRequest) String() string

type GetForecastResponse

type GetForecastResponse struct {
	ForecastRecords []*WeatherForecast `protobuf:"bytes,1,rep,name=forecast_records,json=forecastRecords,proto3" json:"forecast_records,omitempty"`
	// contains filtered or unexported fields
}

func (*GetForecastResponse) Descriptor deprecated

func (*GetForecastResponse) Descriptor() ([]byte, []int)

Deprecated: Use GetForecastResponse.ProtoReflect.Descriptor instead.

func (*GetForecastResponse) GetForecastRecords

func (x *GetForecastResponse) GetForecastRecords() []*WeatherForecast

func (*GetForecastResponse) ProtoMessage

func (*GetForecastResponse) ProtoMessage()

func (*GetForecastResponse) ProtoReflect

func (x *GetForecastResponse) ProtoReflect() protoreflect.Message

func (*GetForecastResponse) Reset

func (x *GetForecastResponse) Reset()

func (*GetForecastResponse) String

func (x *GetForecastResponse) String() string

type Station

type Station interface {
	Name() string
	Latitude() float64
	Longitude() float64
	GetReport(ctx context.Context) (*WeatherReport, error)
	GetForecast(ctx context.Context) ([]*WeatherForecast, error)
}

Station represents a single weather station location.

type UnimplementedWeatherServiceServer

type UnimplementedWeatherServiceServer struct{}

UnimplementedWeatherServiceServer must be embedded to have forward compatible implementations.

NOTE: this should be embedded by value instead of pointer to avoid a nil pointer dereference when methods are called.

func (UnimplementedWeatherServiceServer) GetCurrentReport

func (UnimplementedWeatherServiceServer) GetForecast

type UnsafeWeatherServiceServer

type UnsafeWeatherServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeWeatherServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to WeatherServiceServer will result in compilation errors.

type WeatherCondition

type WeatherCondition struct {
	SummaryIcon WeatherIcon `` /* 136-byte string literal not displayed */
	// In Celsius.
	Temperature float32 `protobuf:"fixed32,21,opt,name=temperature,proto3" json:"temperature,omitempty"`
	// In Celsius. May not be set if there are no wind conditions.
	WindChill float32 `protobuf:"fixed32,22,opt,name=wind_chill,json=windChill,proto3" json:"wind_chill,omitempty"`
	// In Celsius.
	DewPoint float32 `protobuf:"fixed32,23,opt,name=dew_point,json=dewPoint,proto3" json:"dew_point,omitempty"`
	// A % out of 100
	Humidity int32 `protobuf:"varint,24,opt,name=humidity,proto3" json:"humidity,omitempty"`
	// In kilopascals (kPa)
	Pressure float32 `protobuf:"fixed32,25,opt,name=pressure,proto3" json:"pressure,omitempty"`
	// In km/hr
	WindSpeed int32 `protobuf:"varint,26,opt,name=wind_speed,json=windSpeed,proto3" json:"wind_speed,omitempty"`
	// In km
	Visibility int32  `protobuf:"varint,27,opt,name=visibility,proto3" json:"visibility,omitempty"`
	UvIndex    int32  `protobuf:"varint,28,opt,name=uv_index,json=uvIndex,proto3" json:"uv_index,omitempty"`
	Summary    string `protobuf:"bytes,29,opt,name=summary,proto3" json:"summary,omitempty"`
	// contains filtered or unexported fields
}

func (*WeatherCondition) Descriptor deprecated

func (*WeatherCondition) Descriptor() ([]byte, []int)

Deprecated: Use WeatherCondition.ProtoReflect.Descriptor instead.

func (*WeatherCondition) GetDewPoint

func (x *WeatherCondition) GetDewPoint() float32

func (*WeatherCondition) GetHumidity

func (x *WeatherCondition) GetHumidity() int32

func (*WeatherCondition) GetPressure

func (x *WeatherCondition) GetPressure() float32

func (*WeatherCondition) GetSummary

func (x *WeatherCondition) GetSummary() string

func (*WeatherCondition) GetSummaryIcon

func (x *WeatherCondition) GetSummaryIcon() WeatherIcon

func (*WeatherCondition) GetTemperature

func (x *WeatherCondition) GetTemperature() float32

func (*WeatherCondition) GetUvIndex

func (x *WeatherCondition) GetUvIndex() int32

func (*WeatherCondition) GetVisibility

func (x *WeatherCondition) GetVisibility() int32

func (*WeatherCondition) GetWindChill

func (x *WeatherCondition) GetWindChill() float32

func (*WeatherCondition) GetWindSpeed

func (x *WeatherCondition) GetWindSpeed() int32

func (*WeatherCondition) ProtoMessage

func (*WeatherCondition) ProtoMessage()

func (*WeatherCondition) ProtoReflect

func (x *WeatherCondition) ProtoReflect() protoreflect.Message

func (*WeatherCondition) Reset

func (x *WeatherCondition) Reset()

func (*WeatherCondition) String

func (x *WeatherCondition) String() string

type WeatherForecast

type WeatherForecast struct {
	ForecastedFor *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=forecasted_for,json=forecastedFor,proto3" json:"forecasted_for,omitempty"`
	ForecastId    string                 `protobuf:"bytes,2,opt,name=forecast_id,json=forecastId,proto3" json:"forecast_id,omitempty"`
	CreatedAt     *timestamppb.Timestamp `protobuf:"bytes,10,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	UpdatedAt     *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
	Conditions    *WeatherCondition      `protobuf:"bytes,20,opt,name=conditions,proto3" json:"conditions,omitempty"`
	// contains filtered or unexported fields
}

func (*WeatherForecast) Descriptor deprecated

func (*WeatherForecast) Descriptor() ([]byte, []int)

Deprecated: Use WeatherForecast.ProtoReflect.Descriptor instead.

func (*WeatherForecast) GetConditions

func (x *WeatherForecast) GetConditions() *WeatherCondition

func (*WeatherForecast) GetCreatedAt

func (x *WeatherForecast) GetCreatedAt() *timestamppb.Timestamp

func (*WeatherForecast) GetForecastId

func (x *WeatherForecast) GetForecastId() string

func (*WeatherForecast) GetForecastedFor

func (x *WeatherForecast) GetForecastedFor() *timestamppb.Timestamp

func (*WeatherForecast) GetUpdatedAt

func (x *WeatherForecast) GetUpdatedAt() *timestamppb.Timestamp

func (*WeatherForecast) ProtoMessage

func (*WeatherForecast) ProtoMessage()

func (*WeatherForecast) ProtoReflect

func (x *WeatherForecast) ProtoReflect() protoreflect.Message

func (*WeatherForecast) Reset

func (x *WeatherForecast) Reset()

func (*WeatherForecast) String

func (x *WeatherForecast) String() string

type WeatherIcon

type WeatherIcon int32
const (
	WeatherIcon_SUNNY            WeatherIcon = 0
	WeatherIcon_CLOUDY           WeatherIcon = 1
	WeatherIcon_PARTIALLY_CLOUDY WeatherIcon = 2
	WeatherIcon_MOSTLY_CLOUDY    WeatherIcon = 3
	WeatherIcon_RAIN             WeatherIcon = 4
	WeatherIcon_CHANCE_OF_RAIN   WeatherIcon = 5
	WeatherIcon_SNOW             WeatherIcon = 6
	WeatherIcon_CHANCE_OF_SNOW   WeatherIcon = 7
	WeatherIcon_SNOW_SHOWERS     WeatherIcon = 8
	WeatherIcon_THUNDERSTORMS    WeatherIcon = 9
	WeatherIcon_FOG              WeatherIcon = 10
)

func (WeatherIcon) Descriptor

func (WeatherIcon) Enum

func (x WeatherIcon) Enum() *WeatherIcon

func (WeatherIcon) EnumDescriptor deprecated

func (WeatherIcon) EnumDescriptor() ([]byte, []int)

Deprecated: Use WeatherIcon.Descriptor instead.

func (WeatherIcon) Number

func (x WeatherIcon) Number() protoreflect.EnumNumber

func (WeatherIcon) String

func (x WeatherIcon) String() string

func (WeatherIcon) Type

type WeatherReport

type WeatherReport struct {
	ObservedAt    *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=observed_at,json=observedAt,proto3" json:"observed_at,omitempty"`
	ObservationId string                 `protobuf:"bytes,2,opt,name=observation_id,json=observationId,proto3" json:"observation_id,omitempty"`
	CreatedAt     *timestamppb.Timestamp `protobuf:"bytes,10,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	UpdatedAt     *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
	Conditions    *WeatherCondition      `protobuf:"bytes,20,opt,name=conditions,proto3" json:"conditions,omitempty"`
	// contains filtered or unexported fields
}

func (*WeatherReport) Descriptor deprecated

func (*WeatherReport) Descriptor() ([]byte, []int)

Deprecated: Use WeatherReport.ProtoReflect.Descriptor instead.

func (*WeatherReport) GetConditions

func (x *WeatherReport) GetConditions() *WeatherCondition

func (*WeatherReport) GetCreatedAt

func (x *WeatherReport) GetCreatedAt() *timestamppb.Timestamp

func (*WeatherReport) GetObservationId

func (x *WeatherReport) GetObservationId() string

func (*WeatherReport) GetObservedAt

func (x *WeatherReport) GetObservedAt() *timestamppb.Timestamp

func (*WeatherReport) GetUpdatedAt

func (x *WeatherReport) GetUpdatedAt() *timestamppb.Timestamp

func (*WeatherReport) ProtoMessage

func (*WeatherReport) ProtoMessage()

func (*WeatherReport) ProtoReflect

func (x *WeatherReport) ProtoReflect() protoreflect.Message

func (*WeatherReport) Reset

func (x *WeatherReport) Reset()

func (*WeatherReport) String

func (x *WeatherReport) String() string

type WeatherServiceClient

type WeatherServiceClient interface {
	GetCurrentReport(ctx context.Context, in *GetCurrentReportRequest, opts ...grpc.CallOption) (*GetCurrentReportResponse, error)
	GetForecast(ctx context.Context, in *GetForecastRequest, opts ...grpc.CallOption) (*GetForecastResponse, error)
}

WeatherServiceClient is the client API for WeatherService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type WeatherServiceServer

type WeatherServiceServer interface {
	GetCurrentReport(context.Context, *GetCurrentReportRequest) (*GetCurrentReportResponse, error)
	GetForecast(context.Context, *GetForecastRequest) (*GetForecastResponse, error)
	// contains filtered or unexported methods
}

WeatherServiceServer is the server API for WeatherService service. All implementations must embed UnimplementedWeatherServiceServer for forward compatibility.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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