Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ConfigApiPort configuration setting for the port to run the API on. ConfigApiPort = os.Getenv("ApiPort") // ConfigDatabaseConnString configuration setting for the postgres database connection string. ConfigDatabaseConnString = os.Getenv("ApiDatabaseConnectionString") // ConfigSecretKey configuration setting for the secret key to encrypt data with. ConfigSecretKey = os.Getenv("ApiSecretKey") )
var (
// ClaimsID claims lookup string to get the ID for a user.
ClaimsUserID = "Id"
)
Functions ¶
This section is empty.
Types ¶
type ApiResponse ¶
ApiResponse A standard Api response model.
type ApiService ¶ added in v0.1.6
type ApiService struct { Options ApiServiceOptions Server *http.Server }
func NewApiService ¶ added in v0.1.6
func NewApiService(options ApiServiceOptions) *ApiService
func (*ApiService) ListenAndServe ¶ added in v0.1.6
func (s *ApiService) ListenAndServe()
type ApiServiceOptions ¶ added in v0.1.6
type DbService ¶ added in v0.1.6
type DbService struct {
// contains filtered or unexported fields
}
DbService database service.
func NewDbService ¶ added in v0.1.6
NewDbService creates a new DbService instance.
type DbSettings ¶ added in v0.1.6
type DbSettings struct {
// contains filtered or unexported fields
}
DbSettings settings for connecting to the database.
type JwtService ¶
type JwtService struct {
UsersRepository UsersRepository
}
JwtService provides Json Web Token authentication middleware and hashing for use in API microservices.
func NewJwtService ¶
func NewJwtService(r UsersRepository) JwtService
NewJwtService Creates a new JwtService instance, with a UsersRepository.
func (*JwtService) ComparePasswords ¶
func (s *JwtService) ComparePasswords(hash string, password string) error
ComparePasswords compares a hashed and non-hashed password to check if they match. Returns an error if they do not.
func (*JwtService) CreateJwtMiddleware ¶
func (s *JwtService) CreateJwtMiddleware(secretKey string) *jwt.GinJWTMiddleware
CreateJwtMiddleware provides a GIN compatible JWT middleware for authenticating with the API microservices.
func (*JwtService) HashPassword ¶
func (s *JwtService) HashPassword(password string) (string, error)
HashPassword hashes passwords for saving into storage securely. Returns an error if generating a hash fails for any reason.
type LoginRequest ¶
LoginRequest model to represent payload used by callers of the api to request a new JWT token. Payload needs to be in the form of {"username": "...", "password": "..."}
type User ¶
type User struct { // Id is the unique identifier for the user. ID uuid.UUID `json:"id"` // Username is the login name for the user. Username string `json:"username"` // Password is the secure pass for securing the user. Password string `json:"password"` }
User represents an API user and its database structure.
type UsersRepository ¶
UsersRepository provides methods to access data from within a database for storage of api users.
func NewUsersRepository ¶
func NewUsersRepository(conn *sql.DB) UsersRepository
NewUsersRepository creates a UsersRepository instance.
func (*UsersRepository) AddUser ¶ added in v0.1.5
func (r *UsersRepository) AddUser(user User) error
AddUser adds a new user to the repository. Returns any error that occurs or nil if added successfully.
func (*UsersRepository) DeleteUser ¶ added in v0.1.5
func (r *UsersRepository) DeleteUser(ID uuid.UUID) error
DeleteUser removes a user from the repository. Returns any error that occurs or nil if removed successfully.
func (*UsersRepository) GetUserByID ¶ added in v0.1.5
func (r *UsersRepository) GetUserByID(ID uuid.UUID) (*User, error)
GetUserByID gets a user from the repository, using its identifier as the lookup. Returns the user with any errors.
func (*UsersRepository) GetUserByUsername ¶ added in v0.1.5
func (r *UsersRepository) GetUserByUsername(username string) (*User, error)
GetUserByUsername gets a user from the repository, using its username as the lookup. Returns the user with any errors.