n2yo

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

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 7 Imported by: 0

README

n2yo-go

Build Status codecov GoDoc Go Report Card FOSSA Status

Unofficial n2yo Golang client.

Usage

Download and install it:

go get github.com/didasy/n2yo-go

Import it in your code:

import "github.com/didasy/n2yo-go

Simplest default example:

package main

import (
	"encoding/json"
	"fmt"
	"os"

	"github.com/didasy/n2yo-go"
)

func main() {
	apiKey := os.Getenv("N2YO_API_KEY")
	client := n2yo.New(apiKey)
	issNORADID := 25544
	lat := -6.200000
	long := 106.816666
	alt := 5.0
	sec := 1
	days := 1
	minVisibility := 1
	minElevation := 15

	// get ISS TLE
	res, err := client.GetTLE(issNORADID)
	if err != nil {
		panic(err)
	}
	data, err := json.MarshalIndent(res, "", "  ")
	if err != nil {
		panic(err)
	}

	fmt.Println("TLE:", string(data))

	// get ISS position
	res, err = client.GetPositions(issNORADID, lat, long, alt, sec)
	if err != nil {
		panic(err)
	}
	data, err = json.MarshalIndent(res, "", "  ")
	if err != nil {
		panic(err)
	}

	fmt.Println("Positions:", string(data))

	// get ISS visual passes
	res, err = client.GetVisualPasses(issNORADID, lat, long, alt, days, minVisibility)
	if err != nil {
		panic(err)
	}
	data, err = json.MarshalIndent(res, "", "  ")
	if err != nil {
		panic(err)
	}

	fmt.Println("Visual Passes:", string(data))

	// get ISS radio passes
	res, err = client.GetRadioPasses(issNORADID, lat, long, alt, days, minElevation)
	if err != nil {
		panic(err)
	}
	data, err = json.MarshalIndent(res, "", "  ")
	if err != nil {
		panic(err)
	}

	fmt.Println("Radio Passes:", string(data))
}

Documentation

Index

Constants

View Source
const (
	DefaultClientTimeout       = 30 * time.Second
	DefaultMaxTransactionCount = 1000

	APIKeyQuery = "apiKey"
)
View Source
const (
	BaseURL = "https://www.n2yo.com"

	TLEPathFormat          = "/rest/v1/satellite/tle/%d"
	PositionsPathFormat    = "/rest/v1/satellite/positions/%d/%f/%f/%f/%d"
	VisualPassesPathFormat = "/rest/v1/satellite/visualpasses/%d/%f/%f/%f/%d/%d"
	RadioPassesPathFormat  = "/rest/v1/satellite/radiopasses/%d/%f/%f/%f/%d/%d"
)
View Source
const (
	PassTypeVisual = "visual"
	PassTypeRadio  = "radio"
)

Variables

View Source
var (
	ErrMaxTransactionCountReached = errors.New("maximum transactions count reached")
)

Functions

This section is empty.

Types

type Client

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

func (*Client) CustomHTTPClient

func (c *Client) CustomHTTPClient(cl *http.Client)

func (*Client) GetPositions

func (c *Client) GetPositions(id int, obsLat, obsLang, obsAlt float64, seconds int) (r Response, err error)

func (*Client) GetRadioPasses

func (c *Client) GetRadioPasses(id int, obsLat, obsLang, obsAlt float64, days, minElevation int) (r Response, err error)

func (*Client) GetTLE

func (c *Client) GetTLE(id int) (r Response, err error)

func (*Client) GetVisualPasses

func (c *Client) GetVisualPasses(id int, obsLat, obsLang, obsAlt float64, days, minVisibility int) (r Response, err error)

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(url string)

type Info

type Info struct {
	SatelliteID       int    `json:"satid"`
	SatelliteName     string `json:"satname"`
	TransactionsCount int    `json:"transactionscount"`
}

type N2YOer

type N2YOer interface {
	GetTLE(id int) (Response, error)
	GetPositions(id int, obsLat, obsLang, obsAlt float64, seconds int) (Response, error)
	GetVisualPasses(id int, obsLat, obsLang, obsAlt float64, days, minVisibility int) (Response, error)
	GetRadioPasses(id int, obsLat, obsLang, obsAlt float64, days, minElevation int) (Response, error)
	CustomHTTPClient(cl *http.Client)
	SetBaseURL(url string)
}

func New

func New(apiKey string) (c N2YOer)

type Pass

type Pass struct {
	StartAzimuth           float64 `json:"startAz"`
	StartAzimuthCompass    string  `json:"startAzCompass"`
	StartElevation         float64 `json:"startEl"`
	StartUnixTimestamp     int     `json:"startUTC"`
	MaxAzimuth             float64 `json:"maxAz"`
	MaxAzimuthCompass      string  `json:"maxAzCompass"`
	MaxElevation           float64 `json:"maxEl"`
	MaxUnixTimestamp       int     `json:"maxUTC"`
	EndAzimuth             float64 `json:"endAz"`
	EndAzimuthCompass      string  `json:"endAzCompass"`
	EndElevation           float64 `json:"endEl"`
	EndUnixTimestamp       int     `json:"endUTC"`
	VisualMagnitude        float64 `json:",omitempty"`
	VisibleDurationSeconds int     `json:",omitempty"`
}

type Position

type Position struct {
	Latitude            float64 `json:"satlatitude"`
	Longitude           float64 `json:"satlongitude"`
	Azimuth             float64 `json:"azimuth"`
	Elevation           float64 `json:"elevation"`
	RightAscensionAngle float64 `json:"ra"`
	DeclinationAngle    float64 `json:"dec"`
	UnixTimestamp       int     `json:"timestamp"`
}

type Response

type Response struct {
	Error       string     `json:"error,omitempty"`
	Info        Info       `json:"info,omitempty"`
	TLE         string     `json:"tle,omitempty"`
	Positions   []Position `json:"positions,omitempty"`
	Passes      []Pass     `json:"passes,omitempty"`
	PassesCount int        `json:"passescount,omitempty"`
	PassesType  string     `json:"passes_type,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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