config

package
v0.0.0-...-5513633 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config provides configuration management, loading/saving and handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir gets the default data directory for a user.

func DefaultMountpoint

func DefaultMountpoint() string

DefaultMountpoint gets the default local path to mount to for a user.

func HomeDir

func HomeDir(path ...string) string

HomeDir generates a joined path relative to the user's home directory.

Types

type Account

type Account struct {

	// Local path where a Drive directory will be mounted.
	LocalPath string `json:"local_path"`

	// File ID of the remote folder to be synced.
	RemoteId string `json:"remote_id"`

	// OAuth 2.0 Client ID for authorization and token refreshing.
	ClientId string `json:"client_id"`

	// OAuth 2.0 Client ID for authorization and token refreshing.
	ClientSecret string `json:"client_secret"`

	// OAuth 2.0 refresh token.
	RefreshToken string `json:"refresh_token"`
}

Account is the configuration of a single account.

func (*Account) Validate

func (a *Account) Validate() bool

Validate tests whether all required fields are present.

type Config

type Config struct {

	// Base data directory
	DataDir string `json:"-"` // Omits from json marshal/unmarshal.

	// Accounts are the configured accounts.
	Accounts []*Account `json:"accounts"`
}

Config contains the configuration for the running app.

func NewConfig

func NewConfig(dataDir string) *Config

NewConfig creates a new configuration in a given directory.

func (*Config) BlobPath

func (c *Config) BlobPath() string

BlobPath is the path to the blob directory in the data directory.

func (*Config) ConfigPath

func (c *Config) ConfigPath() string

ConfigPath is the path to the config file inside the data directory.

func (*Config) DataPath

func (c *Config) DataPath(path ...string) string

DataPath generates a path relative to the data directory.

func (*Config) FirstAccount

func (c *Config) FirstAccount() *Account

Hack while we only support one account

func (*Config) Load

func (c *Config) Load() error

Load the configuration from the configured location in the data directory.

func (*Config) Marshal

func (c *Config) Marshal() ([]byte, error)

Marshal the configuration to JSON.

func (*Config) MetadataPath

func (c *Config) MetadataPath() string

Metadata path is the path to the metadata database in the data directory.

func (*Config) Read

func (c *Config) Read(r io.Reader) error

Read the configuration from JSON.

func (*Config) Save

func (c *Config) Save() error

Save a config file to the configured location in the data directory.

func (*Config) Setup

func (c *Config) Setup() error

Setup initial config requirements - only need some directories for now.

func (*Config) Validate

func (c *Config) Validate() bool

Validate tests there is at least one account and all accounts are valid.

func (*Config) Write

func (c *Config) Write(w io.Writer) error

Write the configuration as JSON.

Jump to

Keyboard shortcuts

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