Documentation ¶
Index ¶
- Constants
- func CompareHash(encrypted, password string) bool
- func GenerateHash(password string) string
- func GenerateRandomKey() string
- func NewEnvelope(sender int, recipient int, msg string, t int) (*Envelope, *Envelope)
- func NewThread(uid int, withuid int, author string, msg string) (*Thread, *Thread)
- type AuthToken
- type AuthTokenService
- type AuthenticationError
- type CompoundError
- type Envelope
- type EnvelopeService
- type ErrorDetails
- type FormError
- type JSONError
- type JSONResult
- type NullTime
- type PublicEnvelope
- type PublicThread
- type PublicToken
- type RdsService
- type ServerError
- type StringSlice
- type Thread
- type ThreadService
- type User
- type UserError
- type UserService
- type UserWithToken
Constants ¶
const ( MessageTypeText = iota MessageTypePhoto )
const ( UserClassAdmin = "0" UserClassUser = "1" )
const (
EnvelopesLimit = 1000
)
const (
PerPage = 10
)
Variables ¶
This section is empty.
Functions ¶
func CompareHash ¶
CompareHash compares encrypted hash with the plain string. Returns true if the hash is generated from the password.
func GenerateHash ¶
GenerateHash creates a hash from a given string using bcrypt with a cost which makes brute force cracking hard. bcrypt.DefaultCost uses over 0.1 second. Use MinCost (about 40ms) for now.
func GenerateRandomKey ¶
func GenerateRandomKey() string
GenerateRandomKey generates random key with only alphabetical letters.
func NewEnvelope ¶
NewEnvelope creates the incoming and outgoing envelopes. The first envelope is the envelope on the sender's side, and the second envelope is the envelope on the receipt's side.
Types ¶
type AuthToken ¶
type AuthToken struct { ID int `db:"id"` AccessKeyID string `db:"access_key_id"` SecretAccessKey string `db:"secret_access_key"` RefreshToken string `db:"refresh_token"` CreatedAt time.Time `db:"created_at"` ExpiresAt time.Time `db:"expires_at"` ModifiedAt time.Time `db:"modified_at"` UserID int `db:"user_id"` ClientID int `db:"client_id"` IsActive bool `db:"is_active"` IsRefreshable bool `db:"is_refreshable"` Scope StringSlice `db:"scope"` }
func NewAuthToken ¶
func NewAuthToken(uid int, cid int, scope StringSlice) *AuthToken
func (*AuthToken) ToPublicToken ¶
func (at *AuthToken) ToPublicToken() *PublicToken
type AuthTokenService ¶
type AuthenticationError ¶
type AuthenticationError struct {
// contains filtered or unexported fields
}
func NewAuthenticationError ¶
func NewAuthenticationError(msg string) AuthenticationError
func (AuthenticationError) Details ¶
func (c AuthenticationError) Details() ErrorDetails
type CompoundError ¶
type CompoundError interface { Error() string Details() ErrorDetails }
func PersistEnvelope ¶
func PersistEnvelope(p PublicEnvelope, us UserService, es EnvelopeService, ts ThreadService) CompoundError
PersistEnvelope saves thread and 2 envelopes from a PublicEnvelope.
type Envelope ¶
type Envelope struct { ID int `db:"id"` UserID int `db:"user_id"` WithUserID int `db:"with_user_id"` IsIncoming bool `db:"is_incoming"` CreatedAt NullTime `db:"created_at"` DeletedAt NullTime `db:"deleted_at"` ReadAt NullTime `db:"read_at"` Message string `db:"message"` MessageType int `db:"message_type"` }
Envelope represents a row in the envelopes table
func (*Envelope) ToPublic ¶
func (env *Envelope) ToPublic(us UserService) *PublicEnvelope
type EnvelopeService ¶
type EnvelopeService interface { GetByUserIDWithUserID(uid int, withuid int, offset int) ([]*Envelope, error) Create(env *Envelope) error MarkDelete(env *Envelope) (int64, error) MarkRead(env *Envelope) (int64, error) }
EnvelopeService defines the protocol for envelopes
type ErrorDetails ¶
type FormError ¶
type FormError struct {
// contains filtered or unexported fields
}
func NewFormError ¶
func NewFormError(msg string, details ErrorDetails) FormError
func (FormError) Details ¶
func (c FormError) Details() ErrorDetails
type JSONError ¶
type JSONError struct { Code int `json:"code"` Message string `json:"message"` Errors ErrorDetails `json:"errors"` }
type JSONResult ¶
type JSONResult struct { Status string `json:"status"` Data interface{} `json:"data"` Error JSONError `json:"error"` Page int `json:"page"` CurrentPage int `json:"current_page"` PerPage int `json:"per_page"` }
func NewErrorJSONResult ¶
func NewErrorJSONResult(err JSONError) *JSONResult
func NewJSONResult ¶
func NewJSONResult(v interface{}, page int) *JSONResult
NewJSONResult returns a unified JSON response.
type NullTime ¶
NullTime represents a time.Time that may be null. NullTime implements the sql.Scanner interface so it can be used as a scan destination, similar to sql.NullString.
type PublicEnvelope ¶
type PublicThread ¶
type PublicToken ¶
type PublicToken struct { AccessKeyID string `json:"access_key_id"` SecretAccessKey string `json:"secret_access_key"` RefreshToken string `json:"refresh_token"` CreatedAt time.Time `json:"created_at"` ExpiresAt time.Time `json:"expires_at"` ModifiedAt time.Time `json:"modified_at"` IsRefreshable bool `json:"is_refreshable"` }
type RdsService ¶
type RdsService interface { Enqueue(queue string, env PublicEnvelope) CompoundError Dequeue(queue string) (PublicEnvelope, CompoundError) // QM: queue manager AddToQM(key string, queue string) CompoundError QMMembers(key string) ([]string, CompoundError) RemoveFromQM(key string, queue string) CompoundError }
RdsService defines the protocol to use redis
type ServerError ¶
type ServerError struct {
// contains filtered or unexported fields
}
func NewServerError ¶
func NewServerError(msg string) ServerError
func (ServerError) Details ¶
func (c ServerError) Details() ErrorDetails
type StringSlice ¶
type StringSlice []string
StringSlice is one dimension text array in Postgresql https://gist.github.com/adharris/4163702#gistcomment-1356268
func (*StringSlice) Scan ¶
func (s *StringSlice) Scan(src interface{}) error
Scan convert to a slice of strings http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-IO
type Thread ¶
type Thread struct { ID int `db:"id"` UserID int `db:"user_id"` WithUserID int `db:"with_user_id"` AuthorUsername string `db:"author_username"` CreatedAt NullTime `db:"created_at"` LatestMessage string `db:"latest_message"` }
Thread represents a row in the threads table
func (*Thread) ToPublic ¶
func (t *Thread) ToPublic() *PublicThread
type ThreadService ¶
type ThreadService interface { GetByUserID(uid int, offset int) ([]*Thread, error) Upsert(t *Thread) (int64, error) }
ThreadService defines the protocol for threads
type User ¶
type User struct { ID int `db:"id"` Username string `db:"username"` FirstName string `db:"first_name"` LastName string `db:"last_name"` Email string `db:"email"` PhoneNumber string `db:"phone_number"` Password string `db:"password"` IsActive bool `db:"is_active"` CreatedAt NullTime `db:"created_at"` DeactivatedAt NullTime `db:"deactivated_at"` OriginalIP string `db:"original_ip"` UserClass string `db:"user_class"` }
User is the corresponding type for a row in users table
type UserError ¶
type UserError struct {
// contains filtered or unexported fields
}
func NewUserError ¶
func (UserError) Details ¶
func (c UserError) Details() ErrorDetails
type UserService ¶
type UserService interface { GetByID(id int) (*User, error) GetByIDs(ids ...int) ([]*User, error) GetByUsername(uname string) (*User, error) Create(u *User) error Update(u *User) (int64, error) }
UserService defines the protocol for users
type UserWithToken ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Godeps
|
|
_workspace/src/github.com/coopernurse/gorp
Package gorp provides a simple way to marshal Go structs to and from SQL databases.
|
Package gorp provides a simple way to marshal Go structs to and from SQL databases. |
_workspace/src/github.com/dgrijalva/jwt-go
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html See README.md for more info.
|
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html See README.md for more info. |
_workspace/src/github.com/dgrijalva/jwt-go/cmd/jwt
A useful example app.
|
A useful example app. |
_workspace/src/github.com/garyburd/redigo/internal/redistest
Package redistest contains utilities for writing Redigo tests.
|
Package redistest contains utilities for writing Redigo tests. |
_workspace/src/github.com/garyburd/redigo/redis
Package redis is a client for the Redis database.
|
Package redis is a client for the Redis database. |
_workspace/src/github.com/go-errors/errors
Package errors provides errors that have stack-traces.
|
Package errors provides errors that have stack-traces. |
_workspace/src/github.com/golang/glog
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
|
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. |
_workspace/src/github.com/gorilla/context
Package context stores values shared during a request lifetime.
|
Package context stores values shared during a request lifetime. |
_workspace/src/github.com/gorilla/mux
Package gorilla/mux implements a request router and dispatcher.
|
Package gorilla/mux implements a request router and dispatcher. |
_workspace/src/github.com/gorilla/securecookie
Package gorilla/securecookie encodes and decodes authenticated and optionally encrypted cookie values.
|
Package gorilla/securecookie encodes and decodes authenticated and optionally encrypted cookie values. |
_workspace/src/github.com/gorilla/websocket
Package websocket implements the WebSocket protocol defined in RFC 6455.
|
Package websocket implements the WebSocket protocol defined in RFC 6455. |
_workspace/src/github.com/gorilla/websocket/examples/autobahn
Command server is a test server for the Autobahn WebSockets Test Suite.
|
Command server is a test server for the Autobahn WebSockets Test Suite. |
_workspace/src/github.com/lib/pq
Package pq is a pure Go Postgres driver for the database/sql package.
|
Package pq is a pure Go Postgres driver for the database/sql package. |
_workspace/src/github.com/lib/pq/listen_example
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
|
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive. |
_workspace/src/github.com/lib/pq/oid
Package oid contains OID constants as defined by the Postgres server.
|
Package oid contains OID constants as defined by the Postgres server. |
_workspace/src/github.com/stretchr/testify/assert
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. |
_workspace/src/github.com/stretchr/testify/require
Alternative testing tools which stop test execution if test failed.
|
Alternative testing tools which stop test execution if test failed. |
_workspace/src/github.com/stretchr/testify/suite
The suite package contains logic for creating testing suite structs and running the methods on those structs as tests.
|
The suite package contains logic for creating testing suite structs and running the methods on those structs as tests. |
_workspace/src/golang.org/x/crypto/bcrypt
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm.
|
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm. |
_workspace/src/golang.org/x/crypto/blowfish
Package blowfish implements Bruce Schneier's Blowfish encryption algorithm.
|
Package blowfish implements Bruce Schneier's Blowfish encryption algorithm. |