ns1-go.v2: gopkg.in/ns1/ns1-go.v2/rest/model/data Index | Examples | Files

package data

import "gopkg.in/ns1/ns1-go.v2/rest/model/data"

Package data contains definitions for NS1 metadata/sources/feeds/etc.

Index

Examples

Package Files

doc.go feed.go meta.go region.go source.go string.go

func FormatInterface Uses

func FormatInterface(i interface{}) string

FormatInterface takes an interface of types: string, bool, int, float64, []string, map[string]interface{} and FeedPtr, and returns a string representation of said interface

func ParseType Uses

func ParseType(s string) interface{}

ParseType returns an interface containing a string, bool, int, float64, []string, or FeedPtr float64 values with no decimal may be returned as integers, but that should be ok because the api won't know the difference when it's json encoded

func ToCamel Uses

func ToCamel(s string) string

ToCamel converts a string to CamelCase

type Config Uses

type Config map[string]interface{}

Config is a flat mapping where values are simple (no slices/maps).

type Destination Uses

type Destination struct {
    ID  string `json:"destid"`

    // All destinations must point to a record.
    RecordID string `json:"record"`

    // Type is the 'level' at which to apply the filters(on the targeted record).
    // Options:
    //   - answer (highest precedence)
    //   - region
    //   - record (lowest precendence)
    Type string `json:"desttype"`

    SourceID string `json:"-"`
}

Destination is the target resource the receives data from a feed/source.

func NewDestination Uses

func NewDestination() *Destination

NewDestination returns an empty feed destination.

type Feed Uses

type Feed struct {
    ID     string `json:"id,omitempty"`
    Name   string `json:"name"`
    Config Config `json:"config,omitempty"`
    Data   Meta   `json:"data,omitempty"`

    SourceID string
}

Feed wraps an NS1 /data/feeds resource

Code:

// Construct the london data feed.
feed := data.NewFeed(
    "London Feed",
    data.Config{"label": "London-UK"})
fmt.Println(feed.ID) // will be empty string
fmt.Println(feed.Name)
fmt.Println(feed.Config)

Output:

London Feed
map[label:London-UK]

func NewFeed Uses

func NewFeed(name string, cfg Config) *Feed

NewFeed returns a data feed with given name and config.

type FeedPtr Uses

type FeedPtr struct {
    FeedID string `json:"feed,omitempty"`
}

FeedPtr represents the dynamic metadata value in which a feed is providing the value.

type Meta Uses

type Meta struct {

    // Indicates whether or not entity is considered 'up'
    // bool or FeedPtr.
    Up  interface{} `json:"up,omitempty"`

    // Indicates the number of active connections.
    // Values must be positive.
    // int or FeedPtr.
    Connections interface{} `json:"connections,omitempty"`

    // Indicates the number of active requests (HTTP or otherwise).
    // Values must be positive.
    // int or FeedPtr.
    Requests interface{} `json:"requests,omitempty"`

    // Indicates the "load average".
    // Values must be positive, and will be rounded to the nearest tenth.
    // float64 or FeedPtr.
    LoadAvg interface{} `json:"loadavg,omitempty"`

    // The Job ID of a Pulsar telemetry gathering job and routing granularities
    // to associate with.
    // string or FeedPtr.
    Pulsar interface{} `json:"pulsar,omitempty"`

    // Must be between -180.0 and +180.0 where negative
    // indicates South and positive indicates North.
    // e.g., the longitude of the datacenter where a server resides.
    // float64 or FeedPtr.
    Latitude interface{} `json:"latitude,omitempty"`

    // Must be between -180.0 and +180.0 where negative
    // indicates West and positive indicates East.
    // e.g., the longitude of the datacenter where a server resides.
    // float64 or FeedPtr.
    Longitude interface{} `json:"longitude,omitempty"`

    // Valid geographic regions are: 'US-EAST', 'US-CENTRAL', 'US-WEST',
    // 'EUROPE', 'ASIAPAC', 'SOUTH-AMERICA', 'AFRICA'.
    // e.g., the rough geographic location of the Datacenter where a server resides.
    // []string or FeedPtr.
    Georegion interface{} `json:"georegion,omitempty"`

    // Countr(ies) must be specified as ISO3166 2-character country code(s).
    // []string or FeedPtr.
    Country interface{} `json:"country,omitempty"`

    // State(s) must be specified as standard 2-character state code(s).
    // []string or FeedPtr.
    USState interface{} `json:"us_state,omitempty"`

    // Canadian Province(s) must be specified as standard 2-character province
    // code(s).
    // []string or FeedPtr.
    CAProvince interface{} `json:"ca_province,omitempty"`

    // Notes to indicate any necessary details for operators.
    // Up to 256 characters in length.
    // string or FeedPtr.
    Note interface{} `json:"note,omitempty"`

    // IP (v4 and v6) prefixes in CIDR format ("a.b.c.d/mask").
    // May include up to 1000 prefixes.
    // e.g., "1.2.3.4/24"
    // []string or FeedPtr.
    IPPrefixes interface{} `json:"ip_prefixes,omitempty"`

    // Autonomous System (AS) number(s).
    // May include up to 1000 AS numbers.
    // []string or FeedPtr.
    ASN interface{} `json:"asn,omitempty"`

    // Indicates the "priority tier".
    // Lower values indicate higher priority.
    // Values must be positive.
    // int or FeedPtr.
    Priority interface{} `json:"priority,omitempty"`

    // Indicates a weight.
    // Filters that use weights normalize them.
    // Any positive values are allowed.
    // Values between 0 and 100 are recommended for simplicity's sake.
    // float64 or FeedPtr.
    Weight interface{} `json:"weight,omitempty"`

    // Indicates a "low watermark" to use for load shedding.
    // The value should depend on the metric used to determine
    // load (e.g., loadavg, connections, etc).
    // int or FeedPtr.
    LowWatermark interface{} `json:"low_watermark,omitempty"`

    // Indicates a "high watermark" to use for load shedding.
    // The value should depend on the metric used to determine
    // load (e.g., loadavg, connections, etc).
    // int or FeedPtr.
    HighWatermark interface{} `json:"high_watermark,omitempty"`
}

Meta contains information on an entity's metadata table. Metadata key/value pairs are used by a record's filter pipeline during a dns query. All values can be a feed id as well, indicating real-time updates of these values. Structure/Precendence of metadata tables:

- Record
  - Meta <- lowest precendence in filter
  - Region(s)
    - Meta <- middle precedence in filter chain
    - ...
  - Answer(s)
    - Meta <- highest precedence in filter chain
    - ...
  - ...

Code:

feedID := "feed_id"

meta := data.Meta{}
meta.Priority = 1
meta.Up = data.FeedPtr{FeedID: feedID}
fmt.Println(meta.Connections) // will be nil
fmt.Println(meta.Priority)
fmt.Println(meta.Up)

Output:

<nil>
1
{feed_id}

func MetaFromMap Uses

func MetaFromMap(m map[string]interface{}) *Meta

MetaFromMap creates a *Meta and uses reflection to set fields from a map. This will panic if a value for a key is not a string. This it to ensure compatibility with terraform

func (*Meta) StringMap Uses

func (meta *Meta) StringMap() map[string]interface{}

StringMap returns a map[string]interface{} representation of metadata (for use with terraform in nested structures)

func (*Meta) Validate Uses

func (meta *Meta) Validate() (errs []error)

Validate validates metadata fields and returns a list of errors if any are found

type Region Uses

type Region struct {
    Meta Meta `json:"meta,omitempty"`
}

Region is a metadata table with a name/key. Can be thought of as metadata groupings.

type Regions Uses

type Regions map[string]Region

Regions is simply a mapping of Regions inside a record.

Code:

feedPtr := data.FeedPtr{FeedID: "feed_id"}

regions := data.Regions{}
// Set a regions' 'up' metavalue to false('down').
regions["some_region"] = data.Region{
    Meta: data.Meta{Up: false},
}
// Set a regions' 'connections' metavalue to receive from a feed.
regions["other_region"] = data.Region{
    Meta: data.Meta{Connections: feedPtr},
}
fmt.Println(regions["some_region"].Meta.Up)
fmt.Println(regions["some_region"].Meta.Priority)
fmt.Println(regions["other_region"].Meta.Connections)
fmt.Println(regions["other_region"].Meta.Priority)

Output:

false
<nil>
{feed_id}
<nil>

type Source Uses

type Source struct {
    ID  string `json:"id,omitempty"`

    // Human readable name of the source.
    Name string `json:"name"`

    Type   string `json:"sourcetype"`
    Config Config `json:"config,omitempty"`
    Status string `json:"status,omitempty"`

    Feeds []*Feed `json:"feeds,omitempty"`
}

Source wraps an NS1 /data/sources resource

Code:

// Construct an NSONE API data source.
source := data.NewSource("my api source", "nsone_v1")
fmt.Println(source.ID) // will be empty string
fmt.Println(source.Name)
fmt.Println(source.Type)

Output:

my api source
nsone_v1

func NewSource Uses

func NewSource(name string, t string) *Source

NewSource takes a name and type t.

Package data imports 10 packages (graph) and is imported by 16 packages. Updated 2019-12-06. Refresh now. Tools for package owners.