spacewatch

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

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 9 Imported by: 0

README

Go Go Report Card GitHub GitHub go.mod Go version

spacewatch

The International Space Station is a modular space station in low Earth orbit. It is a multinational collaborative project involving five participating space agencies: NASA, Roscosmos, JAXA, ESA, and CSA. The ownership and use of the space station is established by intergovernmental treaties and agreements.

The Spacewatch service is a REST API that provides functionality for tracking the International Space Station. The service's primary function is to provide information if the ISS is visible in the sky at the given moment. We assume the ISS is visible if both conditions are satisfied: the sky cloud coverage is less than 30%, and it is nighttime.

Note: The service is under development, and it is not intended for production use.

development

To use the service at the moment, you need to register at Weatherbit.io to get an API KEY. Once you get the key, you need to export it as an Env Var SPACEWATCH_WEATHER_API_KEY

Make targets useful for development and testing:
$ make
vet                  Run go vet and shadow
check                Run static check analyzer
cover                Run unit tests and generate test coverage report
test                 Run unit tests locally
tidy                 Run go mod tidy and vendor
run                  Run service locally
Run service locally:
$ make run
go run cmd/spacewatch-api/main.go
SPACEWATCH : 2021/12/07 16:56:28.966230 main.go:62: main : Started
SPACEWATCH : 2021/12/07 16:56:28.966388 main.go:69: main : Config :
--web-address=localhost:9000
--web-read-timeout=5s
--web-write-timeout=5s
--web-shutdown-timeout=5s
--web-cache-ttl=10s

SPACEWATCH : 2021/12/07 16:56:29.024535 main.go:96: main : Spacewatch API listening on localhost:9000
Test the service:
$ curl localhost:9000
{"lat":-43.93,"long":-36.43,"timezone":"Atlantic/South_Georgia","cloud_coverage":100,"day_part":"night","is_visible":false}
$ curl localhost:9000
{"lat":-21.71,"long":-7.31,"timezone":"Atlantic/St_Helena","cloud_coverage":9,"day_part":"day","is_visible":true}

Received payload:

{"lat":-21.71,"long":-7.31,"timezone":"Atlantic/St_Helena","cloud_coverage":9,"day_part":"day","is_visible":true}
  • lat/long - ISS coordinates at the time of the request
  • timezone - where is ISS
  • clud_coverage in %
  • day_part - is it day or night in the timezone
  • is_visible - indicates if the ISS can be seen on the sky (cloud coverage <= 30% and night)

roadmap

  • implement server-side caching (minimize load on third party services)
  • replace weather provider (currently there are limitations with no of requests)
  • add Caddy server as a proxy in front of the service (TLS, request rate limiting)
  • add a healthcheck endpoint
  • add request tracing and metrics (Prometheus)
  • use context for requests cancellations
  • implement middleware (and move logging functionality)
  • configure autodeployment (GitHub Actions)
  • register the service in the RapidAPI for public use

tbd

  • add gRPC interface

Documentation

Overview

Package spacewatch provides functionality for checking if the International Space Station is visible from the Earth.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCacheClient

func NewCacheClient(ttl time.Duration) (*cache.Client, error)

NewCacheClient knows how to construct default in-memory cache with the specified TTL parameter.

Types

type ISSStatusHandler

type ISSStatusHandler struct {
	ApiKey        string
	Log           *log.Logger
	StatusChecker func(apikey string) (Status, error)
}

func (*ISSStatusHandler) Get

type Location

type Location struct {
	Lat  float64
	Long float64
}

Location holds coordinates information.

func GetISSLocation

func GetISSLocation() (Location, error)

GetISSLocation is a high level function that knows how to return current location (lat/long) of the International Space Station.

GetISSLocation uses default implementation of the iss client.

type Status

type Status struct {
	// Lat/Long are coordinates of the ISS.
	Lat           float64 `json:"lat"`
	Long          float64 `json:"long"`
	Timezone      string  `json:"timezone"`
	CloudCoverage int     `json:"cloud_coverage"`
	DayPart       string  `json:"day_part"`

	// IsVisible is calculated based on
	// cloud coverage and part of the day.
	IsVisible bool `json:"is_visible"`
}

Status represents the ISS status report.

func GetISSStatus

func GetISSStatus(apikey string) (Status, error)

GetISSStatus holds the core logic used for generating ISS status update. It takes APIKEY required by the undelying weather service and return the Status struct, or error if any of the internal operation fail.

GetISSStatus leverages deafult clients for ISS location and weather status.

Directories

Path Synopsis
cmd
Package iss provides functions for reading position latitude/longitude of the International Space Station.
Package iss provides functions for reading position latitude/longitude of the International Space Station.
Package weather provides functions for checking various weather conditions for given latitude and longitude.
Package weather provides functions for checking various weather conditions for given latitude and longitude.

Jump to

Keyboard shortcuts

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