shared

package module
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 19 Imported by: 18

README

shared

Library code shared among our repositories

vin utils

Use the VIN type for strings that are VIN's and it gets some basic decoding functionality (eg. year, or tesla model).

config loader

Convention over configuration library for typed configurations that can read from yaml file or env vars. Provides an opinionated way of dealing with configurations: for local development we want to use yaml config files, and on higher level environments we want settings to come from environment variables (we use kubernetes). Supported types are: string, int, int64, bool.

gRPC library

We should probably put these in the repositories of the services that own them, but we are putting this off for now. To make changes to the current suite for, e.g., the devices API, run

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/devices/*.proto

Linting

brew install golangci-lint

golangci-lint run

This should use the settings from .golangci.yml, which you can override.

If brew version does not work, download from https://github.com/golangci/golangci-lint/releases (darwin arm64 if M1), then copy to /usr/local/bin and sudo xattr -c golangci-lint

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig added in v0.1.7

func LoadConfig[S any](filePath string) (S, error)

LoadConfig fills in all the values in the Settings from local yml file (for dev) and env vars (for deployments)

Types

type Cipher added in v0.1.13

type Cipher interface {
	Decrypt(s string) (string, error)
	Encrypt(s string) (string, error)
}

Cipher is an interface for something that can encrypt and decrypt strings.

type CloudEvent added in v0.2.0

type CloudEvent[A any] struct {
	// ID is an identifier for the event. The combination of ID and Source must
	// be unique.
	ID string `json:"id"`
	// Source is a URI reference describing the producer of the event.
	Source string `json:"source"`
	// SpecVersion is the version of CloudEvents specification used. For now,
	// this is always "1.0".
	SpecVersion string `json:"specversion"`
	// Subject is an optional field identifying the subject of the event within
	// the context of the event producer.
	Subject string `json:"subject"`
	// Time is an optional field giving the time at which the event occurred.
	Time time.Time `json:"time"`
	// Type describes the type of event. It should generally be a reverse-DNS
	// name.
	Type string `json:"type"`
	// Data contains domain-specific information about the event.
	Data A `json:"data"`
}

CloudEvent represents an event according to the CloudEvents spec. See https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md

type CloudEventHeaders added in v0.1.3

type CloudEventHeaders struct {
	ID          string    `json:"id"`
	Source      string    `json:"source"`
	SpecVersion string    `json:"specversion"`
	Subject     string    `json:"subject"`
	Time        time.Time `json:"time"`
	Type        string    `json:"type"`
}

CloudEventHeaders contains the fields common to all CloudEvent messages.

type HTTPClientWrapper added in v0.1.11

type HTTPClientWrapper interface {
	ExecuteRequest(path, method string, body []byte) (*http.Response, error)
}

func NewHTTPClientWrapper added in v0.1.11

func NewHTTPClientWrapper(baseURL, torProxyURL string, timeoutSeconds time.Duration, headers map[string]string, addJSONHeaders bool) (HTTPClientWrapper, error)

type JSONCodec added in v0.4.0

type JSONCodec[A any] struct{}

TODO(elffjs): Move this to DIMO-Network/shared.

func (*JSONCodec[A]) Decode added in v0.4.0

func (c *JSONCodec[A]) Decode(data []byte) (interface{}, error)

func (*JSONCodec[A]) Encode added in v0.4.0

func (c *JSONCodec[A]) Encode(value interface{}) ([]byte, error)

type KMSCipher added in v0.1.13

type KMSCipher struct {
	Client *kms.Client
	KeyID  string
}

KMSCipher is a Cipher that performs symmetric encryption with an AWS KMS key. TODO(elffjs): Give this a proper constructor. TODO(elffjs): Figure out key rotation in a couple of weeks.

func (*KMSCipher) Decrypt added in v0.1.13

func (e *KMSCipher) Decrypt(s string) (string, error)

func (*KMSCipher) Encrypt added in v0.1.13

func (e *KMSCipher) Encrypt(s string) (string, error)

type ROT13Cipher added in v0.1.13

type ROT13Cipher struct{}

ROT13Cipher is a Cipher that implements ROT13 encryption. Do not use this outside of tests!

func (*ROT13Cipher) Decrypt added in v0.1.13

func (e *ROT13Cipher) Decrypt(s string) (string, error)

func (*ROT13Cipher) Encrypt added in v0.1.13

func (e *ROT13Cipher) Encrypt(s string) (string, error)

type StringSet added in v0.1.2

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

StringSet offers a nice api to deal with string lists

func NewStringSet added in v0.1.2

func NewStringSet() *StringSet

func (*StringSet) Add added in v0.1.2

func (s *StringSet) Add(st string)

func (*StringSet) Contains added in v0.1.2

func (s *StringSet) Contains(st string) bool

func (*StringSet) Len added in v0.1.2

func (s *StringSet) Len() int

func (*StringSet) Slice added in v0.1.2

func (s *StringSet) Slice() []string

type VIN

type VIN string

func (VIN) String added in v0.1.1

func (v VIN) String() string

func (VIN) TeslaModel added in v0.1.3

func (v VIN) TeslaModel() string

func (VIN) Year

func (v VIN) Year() int

Year will decode the year portion from the VIN from 1994 to 2023. returns 0 if out of range. VIN nomenclature only allows for 30 year timespans, then repeats, ie. 2023 = 1993

Directories

Path Synopsis
api
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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