Add IAM scaffold modules

This commit is contained in:
2026-02-03 10:05:53 +08:00
parent bc69ad4e33
commit 66e438978e
21 changed files with 156 additions and 0 deletions

7
iam/cmd/iam/main.go Normal file
View File

@@ -0,0 +1,7 @@
package main
import "todo-vibe-coding/iam/internal/service"
func main() {
_ = service.NewIAM()
}

View File

@@ -0,0 +1,3 @@
# deployments
Deployment manifests placeholder.

8
iam/docs/README.md Normal file
View File

@@ -0,0 +1,8 @@
# IAM Demo Structure
This folder is a lightweight example showing how files can be split by responsibility.
- cmd/iam/main.go creates the service.
- internal/service wires dependencies.
- internal/auth/jwt holds token logic.
- internal/repo provides data access interfaces.

View File

@@ -0,0 +1,7 @@
package http
type Router struct{}
func NewRouter() *Router {
return &Router{}
}

View File

@@ -0,0 +1,7 @@
package middleware
type Logger struct{}
func NewLogger() *Logger {
return &Logger{}
}

View File

@@ -0,0 +1,7 @@
package jwks
type Store struct{}
func NewStore() *Store {
return &Store{}
}

View File

@@ -0,0 +1,9 @@
package jwt
type Manager struct {
secret string
}
func NewManager(secret string) *Manager {
return &Manager{secret: secret}
}

View File

@@ -0,0 +1,7 @@
package keys
type Manager struct{}
func NewManager() *Manager {
return &Manager{}
}

View File

@@ -0,0 +1,7 @@
package refresh
type Store struct{}
func NewStore() *Store {
return &Store{}
}

View File

@@ -0,0 +1,7 @@
package revoke
type Tracker struct{}
func NewTracker() *Tracker {
return &Tracker{}
}

View File

@@ -0,0 +1,9 @@
package config
type Config struct {
Issuer string
}
func Default() Config {
return Config{Issuer: "iam-demo"}
}

View File

@@ -0,0 +1,11 @@
package domain
type User struct {
ID int64
Name string
}
type Role struct {
ID int64
Name string
}

View File

@@ -0,0 +1,5 @@
package errors
import "errors"
var ErrUnauthorized = errors.New("unauthorized")

View File

@@ -0,0 +1,20 @@
package repo
type User struct {
ID int64
Name string
}
type UserStore interface {
FindByID(id int64) (*User, error)
}
type inMemoryUserStore struct{}
func NewInMemoryUserStore() UserStore {
return &inMemoryUserStore{}
}
func (s *inMemoryUserStore) FindByID(id int64) (*User, error) {
return &User{ID: id, Name: "demo"}, nil
}

View File

@@ -0,0 +1,18 @@
package service
import (
"todo-vibe-coding/iam/internal/auth/jwt"
"todo-vibe-coding/iam/internal/repo"
)
type IAM struct {
tokens *jwt.Manager
users repo.UserStore
}
func NewIAM() *IAM {
return &IAM{
tokens: jwt.NewManager("dev-secret"),
users: repo.NewInMemoryUserStore(),
}
}

View File

@@ -0,0 +1,7 @@
package transport
type Emitter struct{}
func NewEmitter() *Emitter {
return &Emitter{}
}

5
iam/internal/util/ids.go Normal file
View File

@@ -0,0 +1,5 @@
package util
func NextID() int64 {
return 1
}

3
iam/migrations/README.md Normal file
View File

@@ -0,0 +1,3 @@
# migrations
Database migrations placeholder.

3
iam/pkg/README.md Normal file
View File

@@ -0,0 +1,3 @@
# pkg
Shared packages for reuse across services (placeholder).

3
iam/scripts/README.md Normal file
View File

@@ -0,0 +1,3 @@
# scripts
Ops scripts placeholder.

3
iam/test/README.md Normal file
View File

@@ -0,0 +1,3 @@
# test
Integration tests placeholder.