login-api

command module
v0.0.0-...-08789e6 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 4 Imported by: 0

README

Login API in Golang

This project is a sample implementation of a login API in Golang, using Echo and JWT, and GORM as the database.

Features

  • User registration (sign up)
  • User authentication (sign in)
  • User logout (sign out)
  • JWT-based authentication

Project Structure

rbac-api/
├── main.go
├── db/
│ └── db.go
├── handlers/
│ └── auth.go
├── models/
│ └── user.go
└── utils/
└── jwt.go

Installation

  1. Clone the repository:
git clone https://github.com/aleksanderpalamar/login-api.git
cd login-api
  1. Install the dependencies: go mod download
  2. Build the application: go build
  3. Run the applications: ./main

Running the Application

To start the application, run:

go run main.go

The server will start on http://localhost:3000.

API Endpoints

  • Sign Up
  • URL: /signup
  • Method: POST
  • Request Body:
{
  "username": "testuser",
  "password": "testpass",
  "role": "user"
}
  • Response:
{
  "message": "User created successfully"
}

Sign Out

  • URL: /signout
  • Method: POST
  • Response:
{
  "message": "signed out"
}

Utility Functions

JWT Utility The JWT utility provides functions for generating and validating JWT tokens.

GenerateJWT Generates a JWT token for a given username.

func GenerateToken(username, password string) (string, error)

ValidateJWT Validates a given JWT token.

func ValidateJWT(tokenString string) (*Claims, error)

Dependencies

Echo - High performance, minimalist Go web framework JWT - JWT (JSON Web Tokens) implementation in Golang

License

This project is licensed under the MIT License. See the LICENSE file for details.

Credits

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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