leancloud

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 23 Imported by: 10

Documentation

Index

Constants

View Source
const Version = "0.3.2"

Variables

This section is empty.

Functions

This section is empty.

Types

type ACL

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

ACL include permission group of object

func NewACL

func NewACL() *ACL

NewACL constructs a new ACL

func NewACLWithUser

func NewACLWithUser(user *User) *ACL

func (*ACL) GetPublicReadAccess

func (acl *ACL) GetPublicReadAccess() bool

func (*ACL) GetPublicWriteAccess

func (acl *ACL) GetPublicWriteAccess() bool

func (*ACL) GetReadAccess

func (acl *ACL) GetReadAccess(user *User) bool

func (*ACL) GetRoleReadAccess

func (acl *ACL) GetRoleReadAccess(role *Role) bool

func (*ACL) GetRoleWriteAccess

func (acl *ACL) GetRoleWriteAccess(role *Role) bool

func (*ACL) GetWriteAccess

func (acl *ACL) GetWriteAccess(user *User) bool

func (*ACL) SetPublicReadAccess

func (acl *ACL) SetPublicReadAccess(allowed bool)

func (*ACL) SetPublicWriteAccess

func (acl *ACL) SetPublicWriteAccess(allowed bool)

func (*ACL) SetReadAccess

func (acl *ACL) SetReadAccess(user *User, allowed bool)

func (*ACL) SetRoleReadAccess

func (acl *ACL) SetRoleReadAccess(role *Role, allowed bool)

func (*ACL) SetRoleWriteAccess

func (acl *ACL) SetRoleWriteAccess(role *Role, allowed bool)

func (*ACL) SetWriteAccess

func (acl *ACL) SetWriteAccess(user *User, allowed bool)

type AuthData

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

func NewAuthData

func NewAuthData() *AuthData

func (*AuthData) Get

func (auth *AuthData) Get(provider string) map[string]interface{}

func (*AuthData) Set

func (auth *AuthData) Set(provider string, data map[string]interface{})

func (*AuthData) SetAnonymous

func (auth *AuthData) SetAnonymous(data map[string]interface{})

type AuthOption

type AuthOption interface {
	// contains filtered or unexported methods
}

func UseMasterKey

func UseMasterKey(useMasterKey bool) AuthOption

func UseSessionToken

func UseSessionToken(sessionToken string) AuthOption

func UseUser

func UseUser(user *User) AuthOption

type Class

type Class struct {
	Name string
	// contains filtered or unexported fields
}

func (*Class) Create

func (ref *Class) Create(object interface{}, authOptions ...AuthOption) (*ObjectRef, error)

Create write the Object to the Storage from the custom structure/bare Object/map.

func (*Class) ID

func (ref *Class) ID(id string) *ObjectRef

ID constructs reference with objectId and className

func (*Class) NewQuery

func (ref *Class) NewQuery() *Query

NewQuery constructs a new Query for general Class

type ClassHookRequest

type ClassHookRequest struct {
	Object *Object
	User   *User
	Meta   map[string]string
}

ClassHookRequest contains object and user passed by Class hook calling

func (*ClassHookRequest) UpdatedKeys

func (r *ClassHookRequest) UpdatedKeys() []string

UpdatedKeys return keys which would be updated, only valid in beforeUpdate hook

type Client

type Client struct {
	Users Users
	Files Files
	Roles Roles
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options *ClientOptions) *Client

NewClient constructs a client from parameters

func NewEnvClient

func NewEnvClient() *Client

NewEnvClient constructs a client from environment variables

func (*Client) Class

func (client *Client) Class(name string) *Class

Class constructs a reference of Class

func (*Client) File

func (client *Client) File(id string) *FileRef

File construct a new reference to a _File object by given objectId

func (*Client) Object

func (client *Client) Object(object interface{}) *ObjectRef

func (*Client) RPC added in v0.3.0

func (client *Client) RPC(name string, params interface{}, results interface{}, runOptions ...RunOption) error

Call cloud function remotely, bind response into `results`

func (*Client) Role

func (client *Client) Role(id string) *RoleRef

func (*Client) Run added in v0.3.0

func (client *Client) Run(name string, params interface{}, runOptions ...RunOption) (interface{}, error)

Call cloud funcion remotely

func (*Client) SetProduction added in v0.3.2

func (client *Client) SetProduction(production bool)

SetProduction sets the production environment

func (*Client) User

func (client *Client) User(user interface{}) *UserRef

type ClientOptions

type ClientOptions struct {
	AppID      string
	AppKey     string
	MasterKey  string
	ServerURL  string
	Production string
}

type CloudEngine added in v0.3.0

type CloudEngine interface {
	Init(client *Client)
	Handler() http.Handler

	Run(name string, params interface{}, runOptions ...RunOption) (interface{}, error)
	RPC(name string, params interface{}, results interface{}, runOptions ...RunOption) error

	Define(name string, fn func(*FunctionRequest) (interface{}, error), defineOptions ...DefineOption)

	BeforeSave(class string, fn func(*ClassHookRequest) (interface{}, error))
	AfterSave(class string, fn func(*ClassHookRequest) error)
	BeforeUpdate(class string, fn func(*ClassHookRequest) (interface{}, error))
	AfterUpdate(class string, fn func(*ClassHookRequest) error)
	BeforeDelete(class string, fn func(*ClassHookRequest) (interface{}, error))
	AfterDelete(class string, fn func(*ClassHookRequest) error)
	OnVerified(verifyType string, fn func(*ClassHookRequest) error)
	OnLogin(fn func(*ClassHookRequest) error)

	OnIMMessageReceived(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMReceiversOffline(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMMessageSent(fn func(*RealtimeHookRequest) error)
	OnIMMessageUpdate(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMConversationStart(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMConversationStarted(fn func(*RealtimeHookRequest) error)
	OnIMConversationAdd(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMConversationRemove(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMConversationAdded(fn func(*RealtimeHookRequest) error)
	OnIMConversationRemoved(fn func(*RealtimeHookRequest) error)
	OnIMConversationUpdate(fn func(*RealtimeHookRequest) (interface{}, error))
	OnIMClientOnline(fn func(*RealtimeHookRequest) error)
	OnIMClientOffline(fn func(*RealtimeHookRequest) error)
	// contains filtered or unexported methods
}
var Engine CloudEngine

type CloudError added in v0.2.0

type CloudError struct {
	Code       int    `json:"code"`
	Message    string `json:"error"`
	StatusCode int    `json:"-"`
	// contains filtered or unexported fields
}

CloudError contains user-defined error

func (CloudError) Error added in v0.2.0

func (err CloudError) Error() string

type DefineOption

type DefineOption interface {
	// contains filtered or unexported methods
}

DefineOption apply options for definition of Cloud Function

func WithInternal

func WithInternal() DefineOption

WithInternal restricts that the Cloud Function can only be executed in LeanEngine

func WithoutFetchUser

func WithoutFetchUser() DefineOption

WithoutFetchUser don't fetch current user originated the request

type File

type File struct {
	Object
	Key      string                 `json:"key"`
	Name     string                 `json:"name"`
	Provider string                 `json:"provider"`
	Bucket   string                 `json:"bucket"`
	MIME     string                 `json:"mime_type"`
	URL      string                 `json:"url"`
	Size     int64                  `json:"size"`
	MetaData map[string]interface{} `json:"metadata"`
}

type FileRef

type FileRef struct {
	ID string
	// contains filtered or unexported fields
}

FileRef refer to a File object in _File class

func (*FileRef) Destroy

func (ref *FileRef) Destroy(authOptions ...AuthOption) error

Destroy delete the referred _File object

func (*FileRef) Get

func (ref *FileRef) Get(file *File, authOptions ...AuthOption) error

Get fetch the referred _File object

type Files

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

func (*Files) NewQuery added in v0.2.0

func (ref *Files) NewQuery() *Query

func (*Files) Upload

func (ref *Files) Upload(file *File, reader io.ReadSeeker, authOptions ...AuthOption) error

Upload transfer the file to cloud storage and create a File object in _File class

func (*Files) UploadFromLocalFile added in v0.2.0

func (ref *Files) UploadFromLocalFile(file *File, path string, authOptions ...AuthOption) error

UploadFromFile transfer the file given by path to cloud storage and create an object in _File class

func (*Files) UploadFromURL

func (ref *Files) UploadFromURL(file *File, authOptions ...AuthOption) error

UploadFromURL create an object of file in _File class with given file's url

type FunctionRequest

type FunctionRequest struct {
	Params       interface{}
	CurrentUser  *User
	SessionToken string
	Meta         map[string]string
}

FunctionRequest contains request information of Cloud Function

type GeoPoint

type GeoPoint struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

GeoPoint contains location's latitude and longitude

func (*GeoPoint) KilometersTo

func (point *GeoPoint) KilometersTo(target *GeoPoint) float64

KilometersTo return the distance from this GeoPoint to another in kilometers

func (*GeoPoint) MilesTo

func (point *GeoPoint) MilesTo(target *GeoPoint) float64

MilesTo return the distance from this GeoPoint to another in miles

func (*GeoPoint) RadiansTo

func (point *GeoPoint) RadiansTo(target *GeoPoint) float64

RadiansTo return the distance from this GeoPoint to another in radians

type Object

type Object struct {
	ID        string    `json:"objectId"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	// contains filtered or unexported fields
}

Object contains full data of Object. Object could also be metadata for custom structure

func (*Object) ACL

func (object *Object) ACL() *ACL

ACL returns ACL value

func (*Object) Bool

func (object *Object) Bool(key string) bool

Bool returns boolean value of the key

func (*Object) Bytes

func (object *Object) Bytes(key string) []byte

Bytes returns []byte value of the key

func (*Object) Clone

func (object *Object) Clone(dst interface{}) error

Clone binds Object to user-defined type

func (*Object) Date

func (object *Object) Date(key string) *time.Time

Date returns time.Time value of the key

func (*Object) File

func (object *Object) File(key string) *File

File returns File value of the key

func (*Object) Float

func (object *Object) Float(key string) float64

Float returns float64 value of the key

func (*Object) GeoPoint

func (object *Object) GeoPoint(key string) *GeoPoint

GeoPoint returns GeoPoint value of the key

func (*Object) Get

func (object *Object) Get(key string) interface{}

Get returns value of the key

func (*Object) Included

func (object *Object) Included() bool

Included shows whether the Object is a included Pointer

func (*Object) Int

func (object *Object) Int(key string) int64

Int returns int64 value of the key

func (*Object) IsPointer

func (object *Object) IsPointer() bool

IsPointer shows whether the Object is a Pointer

func (*Object) Raw

func (object *Object) Raw() map[string]interface{}

Raw returns raw data of Object in form of map

func (*Object) String

func (object *Object) String(key string) string

String returns string value of the key

type ObjectRef

type ObjectRef struct {
	ID string
	// contains filtered or unexported fields
}

func (*ObjectRef) Destroy

func (ref *ObjectRef) Destroy(authOptions ...AuthOption) error

func (*ObjectRef) Get

func (ref *ObjectRef) Get(object interface{}, authOptions ...AuthOption) error

Get fetchs object from backend

func (*ObjectRef) Set

func (ref *ObjectRef) Set(key string, value interface{}, authOptions ...AuthOption) error

Set manipulate

func (*ObjectRef) Update

func (ref *ObjectRef) Update(diff interface{}, authOptions ...AuthOption) error

func (*ObjectRef) UpdateWithQuery

func (ref *ObjectRef) UpdateWithQuery(diff interface{}, query *Query, authOptions ...AuthOption) error

type Op

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

func OpAdd

func OpAdd(objects interface{}) Op

func OpAddRelation

func OpAddRelation(objects interface{}) Op

func OpAddUnique

func OpAddUnique(objects interface{}) Op

func OpBitAnd

func OpBitAnd(value interface{}) Op

func OpBitOr

func OpBitOr(value interface{}) Op

func OpBitXor

func OpBitXor(value interface{}) Op

func OpDecrement

func OpDecrement(amount interface{}) Op

func OpDelete

func OpDelete() Op

func OpIncrement

func OpIncrement(amount interface{}) Op

func OpRemove

func OpRemove(objects interface{}) Op

func OpRemoveRelation

func OpRemoveRelation(objects interface{}) Op

type ParseResponseError

type ParseResponseError struct {
	ParseError     error
	ResponseHeader http.Header
	ResponseText   string
	StatusCode     int
	URL            string
}

func (*ParseResponseError) Error

func (err *ParseResponseError) Error() string

type Query

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

Query contain parameters of queries

func (*Query) And

func (q *Query) And(queries ...*Query) *Query

func (*Query) Contains

func (q *Query) Contains(key, substring string) *Query

func (*Query) ContainsAll

func (q *Query) ContainsAll(key string, objects interface{}) *Query

func (*Query) Count

func (q *Query) Count(authOptions ...AuthOption) (int, error)

Count returns the count of results of the Query

func (*Query) EqualTo

func (q *Query) EqualTo(key string, value interface{}) *Query

func (*Query) Exists added in v0.3.0

func (q *Query) Exists(key string) *Query

func (*Query) Find

func (q *Query) Find(objects interface{}, authOptions ...AuthOption) error

Find fetch results of the Query

func (*Query) First

func (q *Query) First(object interface{}, authOptions ...AuthOption) error

First fetch the first result of the Query

func (*Query) GreaterThan

func (q *Query) GreaterThan(key string, value interface{}) *Query

func (*Query) GreaterThanOrEqualTo

func (q *Query) GreaterThanOrEqualTo(key string, value interface{}) *Query

func (*Query) In

func (q *Query) In(key string, data interface{}) *Query

func (*Query) Include

func (q *Query) Include(keys ...string) *Query

func (*Query) IncludeACL

func (q *Query) IncludeACL() *Query

func (*Query) LessThan

func (q *Query) LessThan(key string, value interface{}) *Query

func (*Query) LessThanOrEqualTo

func (q *Query) LessThanOrEqualTo(key string, value interface{}) *Query

func (*Query) Limit

func (q *Query) Limit(limit int) *Query

func (*Query) MatchesKeyQuery

func (q *Query) MatchesKeyQuery(key, queryKey string, query *Query) *Query

func (*Query) MatchesQuery

func (q *Query) MatchesQuery(key string, query *Query) *Query

func (*Query) Near

func (q *Query) Near(key string, point *GeoPoint) *Query

func (*Query) NotEqualTo

func (q *Query) NotEqualTo(key string, value interface{}) *Query

func (*Query) NotExists added in v0.3.0

func (q *Query) NotExists(key string) *Query

func (*Query) NotIn

func (q *Query) NotIn(key string, data interface{}) *Query

func (*Query) NotMatchesQuery added in v0.3.0

func (q *Query) NotMatchesQuery(key string, query *Query) *Query

func (*Query) Or

func (q *Query) Or(queries ...*Query) *Query

func (*Query) Order

func (q *Query) Order(keys ...string) *Query

func (*Query) Regexp

func (q *Query) Regexp(key, expr, options string) *Query

func (*Query) Select

func (q *Query) Select(keys ...string) *Query

func (*Query) Skip

func (q *Query) Skip(count int) *Query

func (*Query) StartsWith

func (q *Query) StartsWith(key, prefix string) *Query

func (*Query) WithinGeoBox

func (q *Query) WithinGeoBox(key string, southwest *GeoPoint, northeast *GeoPoint) *Query

func (*Query) WithinKilometers

func (q *Query) WithinKilometers(key string, point *GeoPoint) *Query

func (*Query) WithinMiles

func (q *Query) WithinMiles(key string, point *GeoPoint) *Query

func (*Query) WithinRadians

func (q *Query) WithinRadians(key string, point *GeoPoint) *Query

type RealtimeHookRequest

type RealtimeHookRequest struct {
	Params map[string]interface{}
	Meta   map[string]string
}

RealtimeHookRequest contains parameters passed by RTM hook calling

type Relation

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

func NewRelation

func NewRelation(key, parentClass string) *Relation

func (*Relation) Add

func (relation *Relation) Add(objects ...interface{})

func (*Relation) Remove

func (relation *Relation) Remove(objects ...interface{})

type Role

type Role struct {
	Object
	Name string `json:"name"`
}

type RoleRef

type RoleRef struct {
	ID string
	// contains filtered or unexported fields
}

func (*RoleRef) Destroy

func (ref *RoleRef) Destroy(authOptions ...AuthOption) error

func (*RoleRef) Get

func (ref *RoleRef) Get(authOption ...AuthOption) (*Role, error)

func (*RoleRef) Set

func (ref *RoleRef) Set(field string, value interface{}, authOptions ...AuthOption) error

func (*RoleRef) Update

func (ref *RoleRef) Update(data map[string]interface{}, authOptions ...AuthOption) error

func (*RoleRef) UpdateWithQuery

func (ref *RoleRef) UpdateWithQuery(data map[string]interface{}, authOptions ...AuthOption) error

type Roles

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

func (*Roles) NewQuery added in v0.2.0

func (ref *Roles) NewQuery() *Query

type RunOption

type RunOption interface {
	// contains filtered or unexported methods
}

RunOption apply options for execution of Cloud Function

func WithSessionToken

func WithSessionToken(token string) RunOption

WithSessionToken specifics the sessionToken of the calling

func WithUser

func WithUser(user *User) RunOption

WithUser specifics the user of the calling

type ServerResponseError

type ServerResponseError struct {
	Code       int    `json:"code"`
	Err        string `json:"error"`
	StatusCode int
	URL        string
}

func (*ServerResponseError) Error

func (err *ServerResponseError) Error() string

type User

type User struct {
	Object
	SessionToken        string `json:"sessionToken"`
	Username            string `json:"username"`
	Email               string `json:"email"`
	EmailVerified       bool   `json:"emailVerified"`
	MobilePhoneNumber   string `json:"mobilePhoneNumber"`
	MobilePhoneVerified bool   `json:"mobilePhoneVerified"`
}

User is a local representation of a user persisted to the LeanCloud server.

type UserRef

type UserRef struct {
	ID string
	// contains filtered or unexported fields
}

func (*UserRef) Destroy

func (ref *UserRef) Destroy(authOptions ...AuthOption) error

func (*UserRef) Get

func (ref *UserRef) Get(user interface{}, authOptions ...AuthOption) error

func (*UserRef) Set

func (ref *UserRef) Set(key string, value interface{}, authOptions ...AuthOption) error

func (*UserRef) Update

func (ref *UserRef) Update(diff interface{}, authOptions ...AuthOption) error

func (*UserRef) UpdateWithQuery

func (ref *UserRef) UpdateWithQuery(diff interface{}, query *Query, authOptions ...AuthOption) error

type Users

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

func (*Users) Become

func (ref *Users) Become(sessionToken string) (*User, error)

func (*Users) ID

func (ref *Users) ID(id string) *UserRef

func (*Users) LogIn

func (ref *Users) LogIn(username, password string) (*User, error)

func (*Users) LogInByEmail added in v0.2.0

func (ref *Users) LogInByEmail(email, password string) (*User, error)

func (*Users) LogInByMobilePhoneNumber

func (ref *Users) LogInByMobilePhoneNumber(number, smsCode string) (*User, error)

func (*Users) NewQuery added in v0.2.0

func (ref *Users) NewQuery() *Query

func (*Users) RequestEmailVerify

func (ref *Users) RequestEmailVerify(email string, authOptions ...AuthOption) error

func (*Users) RequestLoginSMSCode

func (ref *Users) RequestLoginSMSCode(number string, authOptions ...AuthOption) error

func (*Users) RequestMobilePhoneVerify

func (ref *Users) RequestMobilePhoneVerify(number string, authOptions ...AuthOption) error

func (*Users) RequestPasswordReset

func (ref *Users) RequestPasswordReset(email string, authOptions ...AuthOption) error

func (*Users) RequestPasswordResetBySMSCode

func (ref *Users) RequestPasswordResetBySMSCode(number string, authOptions ...AuthOption) error

func (*Users) ResetPasswordBySMSCode

func (ref *Users) ResetPasswordBySMSCode(number, smsCode, password string, authOptions ...AuthOption) error

func (*Users) SignUp

func (ref *Users) SignUp(username, password string) (*User, error)

func (*Users) SignUpByEmail added in v0.2.0

func (ref *Users) SignUpByEmail(email, password string) (*User, error)

func (*Users) SignUpByMobilePhone

func (ref *Users) SignUpByMobilePhone(number, smsCode string) (*User, error)

Jump to

Keyboard shortcuts

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