context

package
v0.0.0-...-cd0f3b4 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2016 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package context is the runtime context of GlusterD

This file implements the global runtime context for GlusterD. Any package that needs access to the GlusterD global runtime context just needs to import this package.

Index

Constants

View Source
const (
	MaxOpVersion    = 40000
	APIVersion      = 1
	GlusterdVersion = "4.0-dev"
)

Various version constants that will be used by GD2

Variables

View Source
var (
	MyUUID         uuid.UUID
	Restart        bool // Indicates if its a fresh install or not
	Rest           *rest.GDRest
	OpVersion      int
	EtcdProcessCtx *os.Process
	EtcdClient     etcdclient.Client
	HostIP         string
)

Any object that is a part of the GlusterD context and needs to be available to other packages should be declared here as exported global variables

View Source
var (
	Store *store.GDStore
)

If someone needs to use the GD2 store, all they need to do is just import context and use context.Store

Functions

func AssignEtcdProcessCtx

func AssignEtcdProcessCtx(ctx *os.Process)

AssignEtcdProcessCtx is to assign the etcd ctx in context.EtcdCtx

func GetEtcdMemberAPI

func GetEtcdMemberAPI() etcdclient.MembersAPI

GetEtcdMemberAPI returns the etcd MemberAPI

func Init

func Init()

Init initializes the GlusterD context. This should be called once before doing anything else.

func InitMyUUID

func InitMyUUID() uuid.UUID

InitMyUUID initializes MyUUID by reading the `<config.LocalStateDir>/uuid` file. If the file is not present it generates a new UUID and saves it to the file. If the file is not accessible. initMyUUID panics.

func RegisterStorePrefix

func RegisterStorePrefix(prefix string)

RegisterStorePrefix allows other packages to register prefixes to be initalized on the store. The prefixes will be created on the store during GD2 context intialization

func SetLocalHostIP

func SetLocalHostIP()

SetLocalHostIP sets the local IP address

Types

type Context

type Context struct {
	Log *log.Entry // Functions which are given this context must use this logger to log their data.
	// contains filtered or unexported fields
}

Context is used to carry contextual information across the lifetime of a request or a transaction.

func NewEmptyContext

func NewEmptyContext() *Context

NewEmptyContext returns a new empty Context with no parent, no associated data and the default logger.

func NewLoggingContext

func NewLoggingContext(fields log.Fields) *Context

NewLoggingContext returns a new context with the logger set to log given fields

func (*Context) Delete

func (c *Context) Delete(key string)

Delete deletes the key and attached value Delete doesn't recurse to parents

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get gets the value for the given key if available. Get recursively searches all parent contexts for the key. Returns nil if not found.

func (*Context) NewContext

func (c *Context) NewContext() *Context

NewContext returns a new empty context with given parent

func (*Context) NewLoggingContext

func (c *Context) NewLoggingContext(fields log.Fields) *Context

NewLoggingContext returns a new context with the logger set to log given fields in addition to the parents logging fields

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set attaches the given key-value pair to the context. If the key exists, the value will be updated.

Jump to

Keyboard shortcuts

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