types

package
v0.0.0-...-876d392 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Public publicowner

Public is the owner that matches all other owners

Functions

func NewContentReader

func NewContentReader(lines []ContentLine) (result io.Reader, err error)

NewContentReader streams content lines together into a reader

Types

type ContentLine

type ContentLine struct {
	ID StoreID `bson:"id"`
	//PageNum  int              `bson:"pagenum"`
	Position int      `bson:"position"`
	Content  []string `bson:"content"`
}

ContentLine is a line of content within a file

type ContextKey

type ContextKey byte

ContextKey is used to store connections to a database in the values of a context

const (
	DATABASE ContextKey = iota
	OWNER
	FILE
	STORE
	CONTENT
	TAG
	ACRONYM
	VIEW
)

Context Keys for each type of database connection

type File

type File struct {
	Permission
	ID   FileID   `json:"id" bson:"id"`
	Name string   `json:"name" bson:"name"`
	Date FileTime `json:"date" bson:"date"`
}

File is the meta data and permission values of a file

func (*File) Copy

func (f *File) Copy() FileI

Copy build a new instance of the File

func (*File) GetDate

func (f *File) GetDate() FileTime

GetDate implements FileI

func (*File) GetID

func (f *File) GetID() FileID

GetID implements FileI

func (*File) GetName

func (f *File) GetName() string

GetName implements FileI

func (*File) MarshalBSON

func (f *File) MarshalBSON() ([]byte, error)

MarshalBSON converts file into bson representation

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

MarshalJSON converts file into json representation

func (*File) SetID

func (f *File) SetID(id FileID)

SetID implements FileI

func (*File) SetName

func (f *File) SetName(n string)

SetName implements FileI

func (*File) UnmarshalBSON

func (f *File) UnmarshalBSON(b []byte) error

UnmarshalBSON convert bson to file

func (*File) UnmarshalJSON

func (f *File) UnmarshalJSON(b []byte) error

UnmarshalJSON converts json to File

type FileDecoder

type FileDecoder struct {
	F *File
	W *WebFile
}

FileDecoder Unmarshals as either a File or WebFile

func (*FileDecoder) File

func (fd *FileDecoder) File() FileI

File returns FileI that was decoded

func (*FileDecoder) UnmarshalBSON

func (fd *FileDecoder) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes bson into WebFile or File

func (*FileDecoder) UnmarshalJSON

func (fd *FileDecoder) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes json to either File or WebFile

type FileI

type FileI interface {
	PermissionI
	GetID() FileID
	SetID(FileID)
	GetName() string
	SetName(n string)
	GetDate() FileTime
	Copy() FileI
}

FileI is the interface type to represent a file

type FileID

type FileID struct {
	StoreID
	Stamp []byte `bson:"stamp"`
}

FileID uniquely identifies a file and its associated file store.

func DecodeFileID

func DecodeFileID(h string) (fid FileID, err error)

DecodeFileID produces a FileID from a base64 encoded string, inverse of String().

func NewFileID

func NewFileID(st StoreID) FileID

NewFileID generates a new file id for a particular file store.

func (FileID) Equal

func (f FileID) Equal(oth FileID) bool

Equal is true if the provided FileID is the same value as the FileID

func (FileID) MarshalJSON

func (f FileID) MarshalJSON() ([]byte, error)

MarshalJSON returns the string representation of the FileID in json format

func (FileID) Mutate

func (f FileID) Mutate() FileID

Mutate returns a new FileID that is associated with the same StoreID

func (FileID) String

func (f FileID) String() string

String returns a base64 encoding of the FileID as a string

func (*FileID) UnmarshalJSON

func (f *FileID) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a json string value into a FileID, using DecodeFileID

type FileStore

type FileStore struct {
	ID          StoreID            `json:"id" bson:"id"`
	Content     []byte             `json:"content" bson:"-"`
	ContentType string             `json:"ctype" bson:"ctype"`
	FileSize    int64              `json:"fsize" bson:"fsize"`
	Perr        *dberrs.Processing `json:"err,omitempty" bson:"perr,omitempty"`
}

FileStore represents a file's content

func NewFileStore

func NewFileStore(r io.Reader) (*FileStore, error)

NewFileStore builds a FileStore from a reader of the file content

func (*FileStore) Copy

func (fs *FileStore) Copy() *FileStore

Copy returns a new instance of a FileStore

func (*FileStore) Reader

func (fs *FileStore) Reader() (io.Reader, error)

Reader returns a reader of the file contents

type FileTime

type FileTime struct {
	Upload time.Time `json:"upload" bson:"upload"`
}

FileTime is a store of the relevant times of a file

type Group

type Group struct {
	Permission
	ID   OwnerID `json:"id" bson:"id"`
	Name string  `json:"name" bson:"name"`
	Max  int64   `json:"max,omitempty" bson:"max,omitempty"`
}

Group is the basic Group implementation

func NewGroup

func NewGroup(name string, o Owner) *Group

NewGroup build Group with a particular name and owner

func (*Group) AddMember

func (g *Group) AddMember(o Owner)

AddMember implements GroupI

func (*Group) Copy

func (g *Group) Copy() Owner

Copy Group

func (*Group) Equal

func (g *Group) Equal(o Owner) bool

Equal returns true if the Owner has Equal ID values

func (*Group) GetID

func (g *Group) GetID() OwnerID

GetID implements GroupI

func (*Group) GetMembers

func (g *Group) GetMembers() []Owner

GetMembers implements GroupI

func (*Group) GetName

func (g *Group) GetName() string

GetName implements GroupI

func (*Group) MarshalBSON

func (g *Group) MarshalBSON() ([]byte, error)

MarshalBSON builds bson representation

func (*Group) MarshalJSON

func (g *Group) MarshalJSON() ([]byte, error)

MarshalJSON builds json representation

func (*Group) Match

func (g *Group) Match(o Owner) bool

Match returns true if owner is equal to group, matches group's owner, or matches any of the group's members

func (*Group) MaxFiles

func (g *Group) MaxFiles() int64

MaxFiles returns the maximum number of files that an owner can own

func (*Group) RemoveMember

func (g *Group) RemoveMember(o Owner)

RemoveMember implements GroupI

func (*Group) SetName

func (g *Group) SetName(s string)

SetName implements GroupI

func (*Group) UnmarshalBSON

func (g *Group) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes to Group group still needs Populate to be called inorder to load owner and members

func (*Group) UnmarshalJSON

func (g *Group) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes to Group group still needs Populate called inorder to load owner and members

type GroupI

type GroupI interface {
	Owner
	PermissionI
	SetName(string)
	GetMembers() []Owner
	AddMember(o Owner)
	RemoveMember(o Owner)
}

GroupI is the group interface

type Owner

type Owner interface {
	GetID() OwnerID
	GetName() string
	Match(o Owner) bool
	Equal(o Owner) bool
	Copy() Owner
	MaxFiles() int64 // Maximum file count for owner, 0 indicates to use the default configuration, -1 indicates infinite
}

Owner is the interface for types that can own things

type OwnerID

type OwnerID struct {
	Type        byte    `bson:"type"`
	UserDefined [3]byte `bson:"ud"`
	Stamp       []byte  `bson:"stamp,omitempty"`
}

OwnerID used to uniquely identify owners

func DecodeOwnerIDString

func DecodeOwnerIDString(s string) (oid OwnerID, err error)

DecodeOwnerIDString inverse operation of String()

func GetCookieUID

func GetCookieUID(r *http.Request) (OwnerID, error)

GetCookieUID gets OwnerID of current session

func (OwnerID) Equal

func (oid OwnerID) Equal(oth OwnerID) bool

Equal is true if all fields are equal

func (OwnerID) MarshalJSON

func (oid OwnerID) MarshalJSON() ([]byte, error)

MarshalJSON build json representation of OwnerID

func (OwnerID) Mutate

func (oid OwnerID) Mutate() OwnerID

Mutate creates new OwnerID of the same type

func (OwnerID) String

func (oid OwnerID) String() string

String returns string representation of OwnerID

func (*OwnerID) UnmarshalJSON

func (oid *OwnerID) UnmarshalJSON(b []byte) error

UnmarshalJSON builds OwnerID from json

type Permission

type Permission struct {
	Own  Owner              `json:"own" bson:"own"`
	Perm map[string][]Owner `json:"perm,omitempty" bson:"perm,omitempty"`
	// contains filtered or unexported fields
}

Permission is to be used as an abstract class of objects that are owned

func (*Permission) CheckPerm

func (p *Permission) CheckPerm(o Owner, s string) bool

CheckPerm returns true if owner has particular permission

func (*Permission) CopyPerm

func (p *Permission) CopyPerm(newowner Owner) PermissionI

CopyPerm creates new permission with new owner, if new owner is nil, reuses current owner

func (*Permission) GetOwner

func (p *Permission) GetOwner() Owner

GetOwner returns owner of object

func (*Permission) GetPerm

func (p *Permission) GetPerm(s string) []Owner

GetPerm returns all owners that have a certain permission

func (*Permission) MarshalBSON

func (p *Permission) MarshalBSON() ([]byte, error)

MarshalBSON converts permission to bson

func (*Permission) MarshalJSON

func (p *Permission) MarshalJSON() ([]byte, error)

MarshalJSON converts permission to json

func (*Permission) PermTypes

func (p *Permission) PermTypes() []string

PermTypes returns all permission types that have an associated owner

func (*Permission) Populate

func (p *Permission) Populate(ub PermissionPopulator) error

Populate loads owners from the database after decoding Permission object from json or bson

func (*Permission) SetPerm

func (p *Permission) SetPerm(o Owner, s string, b bool)

SetPerm sets permission for a particular owner

func (*Permission) UnmarshalBSON

func (p *Permission) UnmarshalBSON(b []byte) error

UnmarshalBSON converts bson to permission

func (*Permission) UnmarshalJSON

func (p *Permission) UnmarshalJSON(b []byte) error

UnmarshalJSON converts json to permission

type PermissionI

type PermissionI interface {
	json.Marshaler
	json.Unmarshaler
	bson.Marshaler
	bson.Unmarshaler
	GetOwner() Owner
	CheckPerm(Owner, string) bool
	GetPerm(string) []Owner
	PermTypes() []string
	SetPerm(Owner, string, bool)
	CopyPerm(Owner) PermissionI
	Populate(PermissionPopulator) error
}

PermissionI interface for Permission Object that can be owned

type PermissionPopulator

type PermissionPopulator interface {
	Get(OwnerID) (Owner, error)
}

PermissionPopulator is an iterface type for Populating Permission Objects with Populate Actions Most likely used with database.Ownerbase type

type StoreID

type StoreID struct {
	Hash  uint32 `bson:"hash"`
	Stamp uint16 `bson:"stamp"`
}

StoreID is used to uniquely identify a FileStore. Contains a hash of the file's content used to quickly identify copies of the same file.

func DecodeStoreID

func DecodeStoreID(h string) (sid StoreID, err error)

DecodeStoreID returns a StoreID from base64 encoded string, inverse of String()

func NewStoreID

func NewStoreID(r io.Reader) (StoreID, error)

NewStoreID builds a StoreID from a reader of the file's contents

func NewStoreIDComplete

func NewStoreIDComplete(r io.Reader, h hash.Hash32, s uint16) (StoreID, error)

NewStoreIDComplete build a StoreID from a reader of the file's contents, a hash scheme and stamp value

func (StoreID) Equal

func (sid StoreID) Equal(oid StoreID) bool

Equal returns true if the other StoreID has the same value

func (StoreID) Mutate

func (sid StoreID) Mutate() StoreID

Mutate returns a new StoreID with the same hash

func (StoreID) String

func (sid StoreID) String() string

String returns a base64 encoding as a string

func (StoreID) ToNum

func (sid StoreID) ToNum() int64

ToNum converts StoreID to a int64 representation

type User

type User struct {
	ID               OwnerID         `json:"uid" bson:"id"`
	Name             string          `json:"name" bson:"name"`
	Pass             UserCredential  `json:"pass" bson:"pass"`
	Email            string          `json:"email" bson:"email"`
	CookieSig        []byte          `json:"cs" bson:"cs"`
	CookieInactivity time.Time       `json:"ci" bson:"ci"`
	CookieTimeout    time.Time       `json:"ct" bson:"ct"`
	Roles            map[string]bool `json:"roles,omitempty" bson:"roles,omitempty"`
	Space            int64           `json:"space,omitempty" bson:"space,omitempty"`
	Max              int64           `json:"max,omitempty" bson:"max,omitempty"`
}

User basic user object

func NewUser

func NewUser(name, password, email string) *User

NewUser with username, email and password

func (*User) ChangeEmail

func (u *User) ChangeEmail(path string)

ChangeEmail implements UserI

func (*User) CheckCookie

func (u *User) CheckCookie(r *http.Request) bool

CheckCookie returns true if request has cookied session cookies

func (*User) Copy

func (u *User) Copy() Owner

Copy builds a new instance of the User

func (*User) Equal

func (u *User) Equal(o Owner) bool

Equal if id is Equal

func (*User) GetCookieTimeouts

func (u *User) GetCookieTimeouts() (time.Time, time.Time)

GetCookieTimeouts returns current session timeouts

func (*User) GetEmail

func (u *User) GetEmail() string

GetEmail implements UserI

func (*User) GetID

func (u *User) GetID() OwnerID

GetID implements UserI

func (*User) GetLock

func (u *User) GetLock() UserCredentialI

GetLock implements UserI

func (*User) GetName

func (u *User) GetName() string

GetName implements UserI

func (*User) GetRole

func (u *User) GetRole(k string) bool

GetRole is true if user has that role

func (*User) GetRoles

func (u *User) GetRoles() []string

GetRoles returns all roles that user has

func (*User) GetTotalSpace

func (u *User) GetTotalSpace() int64

GetTotalSpace returns current Total Space value of user

func (*User) Match

func (u *User) Match(o Owner) bool

Match returns true if owner is equal to user

func (*User) MaxFiles

func (u *User) MaxFiles() int64

MaxFiles returns the maximum number of files that an owner can own

func (*User) NewCookies

func (u *User) NewCookies(inactivity time.Time, timeout time.Time) []*http.Cookie

NewCookies creates new cookies for a new session

func (*User) RefreshCookie

func (u *User) RefreshCookie(inactive time.Time)

RefreshCookie sets inactivity timeout

func (*User) SetLock

func (u *User) SetLock(c UserCredentialI)

SetLock implements UserI

func (*User) SetRole

func (u *User) SetRole(k string, v bool)

SetRole assigns user to role if v is true, removes role if v is false

type UserCredential

type UserCredential struct {
	Salt []byte `json:"a" bson:"a"`
	Hash []byte `json:"b" bson:"b"`
}

UserCredential is a salt and hashed of a password

func NewUserCredential

func NewUserCredential(pass string) UserCredential

NewUserCredential build UserCredential from password

func (UserCredential) Valid

func (up UserCredential) Valid(credential map[string]interface{}) bool

Valid returns true if credential has the field "pass" has the correct password.

type UserCredentialI

type UserCredentialI interface {
	Valid(c map[string]interface{}) bool
}

UserCredentialI interface representing types that can be used to validate user

type UserI

type UserI interface {
	Owner
	GetLock() UserCredentialI
	SetLock(UserCredentialI)
	NewCookies(time.Time, time.Time) []*http.Cookie
	CheckCookie(*http.Request) bool
	RefreshCookie(time.Time)
	GetCookieTimeouts() (time.Time, time.Time)
	GetRole(string) bool
	GetRoles() []string
	SetRole(string, bool)
	GetEmail() string
	ChangeEmail(string)
	GetTotalSpace() int64
}

UserI interface tyoe for representing users

type ViewStore

type ViewStore struct {
	ID      StoreID `json:"id" bson:"id"`
	Content []byte  `json:"content" bson:"-"`
}

ViewStore represents the PDF representation of a File

func NewViewStore

func NewViewStore(id StoreID, r io.Reader) (*ViewStore, error)

NewViewStore builds ViewStore from a StoreID and Reader of pdf representation

func (*ViewStore) Reader

func (vs *ViewStore) Reader() (io.Reader, error)

Reader returns a reader of the content of a pdf representation of the file

type WebFile

type WebFile struct {
	File
	URL string `json:"url" bson:"url"`
}

WebFile is an extention of a File with URL value

func (*WebFile) Copy

func (wp *WebFile) Copy() FileI

Copy build a new instance of the WebFile

func (*WebFile) MarshalBSON

func (wp *WebFile) MarshalBSON() ([]byte, error)

MarshalBSON converts webfile to bson

func (*WebFile) MarshalJSON

func (wp *WebFile) MarshalJSON() ([]byte, error)

MarshalJSON converts webfile to json

func (*WebFile) UnmarshalBSON

func (wp *WebFile) UnmarshalBSON(b []byte) error

UnmarshalBSON converts bson to file

func (*WebFile) UnmarshalJSON

func (wp *WebFile) UnmarshalJSON(b []byte) error

UnmarshalJSON converts json to File

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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