api

package
v0.0.0-...-fce603d Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MessageGeneralError  = "Ada kesalahan, Silahakan coba beberapa saat lagi."
	MessageUnauthorized  = "Silahkan login terlebih dahulu atau login ulang."
	MessageInvalidLogin  = "Email atau password anda salah."
	MessageAccountExists = "Akun anda sudah terdaftar, silahkan login."
)
View Source
var (
	ErrUnauthorized = errors.New("unauthorized")
)

Functions

func ComparePassword

func ComparePassword(ctx context.Context, hash string, password string) error

func GetContextRequesterID

func GetContextRequesterID(ctx context.Context) uuid.UUID

func HashPassword

func HashPassword(ctx context.Context, password string) (string, error)

func Init

func Init(lg *logging.Logger, db *sql.DB, cache *redis.Pool, opt InitOption)

func NewSession

func NewSession(ctx context.Context, s Session) (string, error)

Create new session of given data.

func RespondError

func RespondError(w http.ResponseWriter, message string, status int)

RespondError writes / respond with JSON-formatted request of given message & http status.

func SessionKey

func SessionKey(token string) string

SessionKey return session cache's key with token parameter.

func SetContextRequesterID

func SetContextRequesterID(ctx context.Context, id uuid.UUID) context.Context

func SetContextSession

func SetContextSession(ctx context.Context, session Session) context.Context

func SetContextToken

func SetContextToken(ctx context.Context, token string) context.Context

func SetRequesterContext

func SetRequesterContext(ctx context.Context, session Session) context.Context

Types

type BaseResponse

type BaseResponse struct {
	Errors []string `json:"errors,omitempty"`
}

type Error

type Error struct {
	Err        error
	StatusCode int
	Message    string
}

func NewError

func NewError(err error, message string, status int) *Error

func NewErrorWrap

func NewErrorWrap(err error, prefix, suffix, message string, status int) *Error

func (*Error) Error

func (e *Error) Error() string

type InitOption

type InitOption struct {
	SessionExpire string
}

type Response

type Response struct {
	Status       string `json:"status"`
	BaseResponse `json:"errors"`
	Data         interface{} `json:"result"`
}

type Session

type Session struct {
	User model.UserModelResponse `json:"user"`
}

func GetSession

func GetSession(ctx context.Context, token string) (Session, error)

GetSession returns session detail of given token string.

func (*Session) RequesterID

func (s *Session) RequesterID() uuid.UUID

Get current session data's identifier / id value.

type SessionData

type SessionData interface {
	// Identifier gets the ID field of current logged in user type.
	Identifier() uuid.UUID
}

type SessionModule

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

type UserDataParam

type UserDataParam struct {
	ID       uuid.UUID `json:"id"`
	Name     string    `json:"name"`
	Email    string    `json:"email"`
	Password string    `json:"password"`
	By       uuid.UUID `json:"by"`
}

type UserLoginParam

type UserLoginParam struct {
	Email      string `json:"email"`
	Password   string `json:"password"`
	RememberMe bool   `json:"remember_me"`
}

type UserModule

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

func NewUserModule

func NewUserModule(db *sql.DB, cache *redis.Pool) *UserModule

func (UserModule) Create

func (UserModule) Delete

func (m UserModule) Delete(ctx context.Context, id uuid.UUID) *Error

func (UserModule) Detail

func (UserModule) List

func (UserModule) Login

func (UserModule) Register

func (UserModule) Update

func (m UserModule) Update(ctx context.Context, param UserDataParam) *Error

Jump to

Keyboard shortcuts

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