model

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: MPL-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	APIKeysFileName = "apikeys.json"
	APIKeysVersion  = 1
)
View Source
const (
	// MapManagerVersion defines current MapManager version.
	MapManagerVersion = 1
	// MapsFileName defines JSON filename
	MapsFileName = "maps.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey added in v0.1.1

type APIKey struct {
	APIKey  string    `json:"apikey"`
	Expires time.Time `json:"expires"`
}

APIKey is a struct for API key.

func NewAPIKey added in v0.1.1

func NewAPIKey() APIKey

NewAPIKey returns new APIKey with random API key for one year.

type APIKeyManager

type APIKeyManager APIKeyManagerV1

APIKeyManager manages API keys. APIKeyManager works as singleton pattern.

func CreateAPIKeyManager

func CreateAPIKeyManager() (*APIKeyManager, error)

CreateAPIKeyManager creates APIKeyManager singleton instance.

func GetAPIKeyManager

func GetAPIKeyManager() *APIKeyManager

GetAPIKeyManager returns instance of APIKeyManager.

func (*APIKeyManager) CreateAPIKey

func (m *APIKeyManager) CreateAPIKey() string

CreateAPIKey generates new API key.

func (*APIKeyManager) DeleteAPIKey

func (m *APIKeyManager) DeleteAPIKey(apiKey string)

DeleteAPIKey deletes given API key.

func (*APIKeyManager) GetAPIKey

func (m *APIKeyManager) GetAPIKey(apiKey string) *APIKey

GetAPIKey returns given API key or nil.

func (*APIKeyManager) GetAPIKeys

func (m *APIKeyManager) GetAPIKeys() []*APIKey

GetAPIKeys returns array of APIKey pointers.

func (*APIKeyManager) IsValidAPIKey

func (m *APIKeyManager) IsValidAPIKey(apiKey string) bool

IsValidAPIKey returns true if given API key is valid.

func (*APIKeyManager) ParseJSON added in v0.1.1

func (m *APIKeyManager) ParseJSON(r io.Reader) error

ParseJSON parses API keys from Reader.

func (*APIKeyManager) Read added in v0.1.1

func (m *APIKeyManager) Read() error

Read decodes JSON data from file.

func (*APIKeyManager) Write added in v0.1.1

func (m *APIKeyManager) Write() error

Write encodes Map.MapFileData to JSON file.

type APIKeyManagerV1 added in v0.1.1

type APIKeyManagerV1 struct {
	Version int                `json:"version"`
	APIKeys map[string]*APIKey `json:"apikeys"`
}

APIKeyManagerV1 is first version of APIKeyManager struct.

type Map

type Map struct {
	MapInfo
	MapFileData
}

Map struct

func NewMap

func NewMap(i MapInfo) *Map

NewMap creates a new Map struct

type MapFileData

type MapFileData MapFileDataV1

MapFileData struct

type MapFileDataV1

type MapFileDataV1 struct {
	Version int `json:"version"`
	// Title2 is a copy from MapInfo.Title
	// Title2 is stored to file so it is permanent and shareable
	Title2    string      `json:"title2"`
	Resources []*Resource `json:"resources"`
}

MapFileDataV1 is version 1 from MapFileData struct.

type MapInfo added in v0.1.2

type MapInfo struct {
	ID     int       `json:"id"`
	Title  string    `json:"title"`
	Base   string    `json:"base"`
	File   string    `json:"file"`
	Opened time.Time `json:"opened"`
}

MapInfo is info struct for FileMap.

type MapInfos added in v0.1.2

type MapInfos []MapInfo

MapInfos is a collection of MapInfo pointers.

func (MapInfos) Len added in v0.1.2

func (slice MapInfos) Len() int

Implementation of sort.Interface for MapInfos.

func (MapInfos) Less added in v0.1.2

func (slice MapInfos) Less(i, j int) bool

func (MapInfos) Swap added in v0.1.2

func (slice MapInfos) Swap(i, j int)

type MapManager

type MapManager MapManagerV1

MapManager manages Maps, reads and stores them. MapManager works as singleton pattern.

func CreateMapManager

func CreateMapManager() (*MapManager, error)

CreateMapManager creates MapManager singleton instance.

func GetMapManager

func GetMapManager() *MapManager

GetMapManager returns instance of MapManager.

func (*MapManager) AddMap

func (mm *MapManager) AddMap(mi MapInfo) (*ProxyMap, error)

AddMap adds new Map and assigns new ID for it.

func (*MapManager) DeleteMap

func (mm *MapManager) DeleteMap(mapID int) bool

DeleteMap deletes Map with given ID.

func (*MapManager) GetMaps

func (mm *MapManager) GetMaps() MapInfos

GetMaps returns MapInfos.

func (*MapManager) GetProxyMap added in v0.2.7

func (mm *MapManager) GetProxyMap(mapID int) *ProxyMap

func (*MapManager) ImportMap

func (mm *MapManager) ImportMap(path string) (*ProxyMap, error)

ImportMap imports new Map from filemap JSON file.

func (*MapManager) ParseJSON added in v0.1.2

func (m *MapManager) ParseJSON(r io.Reader) error

ParseJSON parses API keys from Reader.

func (*MapManager) Read added in v0.1.2

func (m *MapManager) Read() error

Read decodes JSON data from file.

func (*MapManager) UpdateMap added in v0.4.0

func (mm *MapManager) UpdateMap(mapID int, title string, base string, file string)

UpdateMap updates information that goes both to maps.json and map.filemap

func (*MapManager) Write added in v0.1.2

func (m *MapManager) Write() error

Write encodes Map.MapFileData to JSON file.

type MapManagerV1 added in v0.1.2

type MapManagerV1 struct {
	Version  int      `json:"version"`
	MapInfos MapInfos `json:"maps"`
	// contains filtered or unexported fields
}

MapManagerV1 is first version of MapManager struct.

type ProxyMap

type ProxyMap struct {
	*Map
	IsRead  bool
	Changed bool
	// contains filtered or unexported fields
}

ProxyMap is virtual proxy for Map struct

func NewProxyMap

func NewProxyMap(i MapInfo) *ProxyMap

NewProxyMap creates a new ProxyMap

func (*ProxyMap) AddResource

func (p *ProxyMap) AddResource(r *Resource) ResourceID

AddResource adds new resource to map and assigns ID for it. Returns new ID.

func (*ProxyMap) DeleteResource

func (p *ProxyMap) DeleteResource(resourceID ResourceID)

DeleteResource deletes resource from map.

func (*ProxyMap) GetResource added in v0.2.0

func (p *ProxyMap) GetResource(id ResourceID) *Resource

GetResource returns Resource by ResourceID.

func (*ProxyMap) OpenResource added in v0.4.0

func (p *ProxyMap) OpenResource(r *Resource)

func (*ProxyMap) ParseJSON

func (p *ProxyMap) ParseJSON(r io.Reader) error

ParseJSON parses MapFileData from Reader.

func (*ProxyMap) Read

func (p *ProxyMap) Read() error

Read decodes JSON data from file to Map.MapFileData.

func (*ProxyMap) Write

func (p *ProxyMap) Write() error

Write encodes Map.MapFileData to JSON file.

type Resource

type Resource ResourceV1

Resource is alias to the latest Resource version

type ResourceID

type ResourceID int

ResourceID is unique in Map, identifies Resource

type ResourcePos

type ResourcePos ResourcePosV1

ResourcePos defines resource position in 3D space. Alias to the latest ResourcePos version

type ResourcePosV1

type ResourcePosV1 struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

ResourcePosV1 is the first version from ResourcePos struct

type ResourceType

type ResourceType int

ResourceType defines type of Resource

const (
	ResourceFile ResourceType = iota
	ResourceDir
)

Resource type enum

func (ResourceType) String

func (r ResourceType) String() string

Converts ResourceType to string

type ResourceV1

type ResourceV1 struct {
	ResourceID ResourceID   `json:"id"`
	Type       ResourceType `json:"type"`
	Path       string       `json:"path"`
	Pos        ResourcePos  `json:"pos"`
}

ResourceV1 is the first version from Resource struct

Jump to

Keyboard shortcuts

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