Skip to content

Latest commit

 

History

History
89 lines (61 loc) · 1.17 KB

File metadata and controls

89 lines (61 loc) · 1.17 KB

🔐 Auth API (Go)

A simple RESTful authentication API written in Go with user registration, login (JWT), and secure profile access.


📦 Features

  • 📝 Register new users
  • 🔑 Login with username and password
  • 🛡 JWT-based authentication
  • 🗂 JSON-based user storage (no database required)
  • ⚙️ Clean and minimal Go codebase

▶️ Endpoints

📌 POST /register

Registers a new user.

Request Body:

{
  "username": "valera",
  "password": "12345"
}

Response:

{"message":"User registered"}

📌 POST /login

Authenticates a user and returns a JWT token.

Request Body:

{
  "username": "valera",
  "password": "12345"
}

Response:

{"token":"<JWT_TOKEN>"}

📌 GET /me

Returns current user info based on JWT.

Header:

Authorization: Bearer <JWT_TOKEN>

Response:

{"username":"valera"}

🛠 How to Run

# 1. Set JWT secret
export JWT_SECRET="mysecretkey"

# 2. Run server
go run main.go

🌟 Author

A student on the path to Yandex. One step at a time.

GitHub: CraftStick