nirvana

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package nirvana is a demo Nirvana project for migration testing.

Index

Constants

This section is empty.

Variables

View Source
var Descriptor = definition.Descriptor{
	Path: "/",
	Children: []definition.Descriptor{
		{
			Path: "/users",
			Definitions: []definition.Definition{
				{
					Method:      definition.List,
					Function:    ListUsers,
					Description: "List all users",
					Produces:    []string{"application/json"},
					Results:     definition.DataErrorResults("UserListResponse"),
				},
				{
					Method:      definition.Create,
					Function:    CreateUser,
					Description: "Create a new user",
					Consumes:    []string{"application/json"},
					Produces:    []string{"application/json"},
					Parameters: []definition.Parameter{
						{
							Source:      definition.Body,
							Name:        "request",
							Description: "Create user request",
						},
					},
					Results: definition.DataErrorResults("User"),
				},
			},
			Children: []definition.Descriptor{
				{
					Path: "/{id}",
					Definitions: []definition.Definition{
						{
							Method:      definition.Get,
							Function:    GetUser,
							Description: "Get a user by ID",
							Produces:    []string{"application/json"},
							Parameters: []definition.Parameter{
								{
									Source: definition.Path,
									Name:   "id",
								},
							},
							Results: definition.DataErrorResults("User"),
						},
						{
							Method:      definition.Delete,
							Function:    DeleteUser,
							Description: "Delete a user by ID",
							Produces:    []string{"application/json"},
							Parameters: []definition.Parameter{
								{
									Source: definition.Path,
									Name:   "id",
								},
							},
							Results: []definition.Result{definition.ErrorResult()},
						},
					},
				},
			},
		},
		{
			Path: "/health",
			Definitions: []definition.Definition{
				{
					Method:      definition.Get,
					Function:    Health,
					Description: "Health check",
					Produces:    []string{"application/json"},
					Results:     []definition.Result{definition.DataResultFor("HealthResponse")},
				},
			},
		},
	},
}

Descriptor contains all API definitions for the demo.

Functions

func DeleteUser

func DeleteUser(ctx context.Context, id string) error

DeleteUser handles DELETE /users/{id}

func NewServer

func NewServer(port uint16) nirvana.Server

NewServer creates a new Nirvana server for demo.

Types

type CreateUserRequest

type CreateUserRequest struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

CreateUserRequest represents a request to create a user.

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
}

HealthResponse represents a health check response.

func Health

func Health(ctx context.Context) HealthResponse

Health handles GET /health

type User

type User struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	CreatedAt string `json:"created_at"`
}

User represents a user entity.

func CreateUser

func CreateUser(ctx context.Context, req CreateUserRequest) (*User, error)

CreateUser handles POST /users

func GetUser

func GetUser(ctx context.Context, id string) (*User, error)

GetUser handles GET /users/{id}

func ListUsers

func ListUsers(ctx context.Context) ([]User, error)

ListUsers handles GET /users

type UserListResponse

type UserListResponse struct {
	Items      []User `json:"items"`
	TotalCount int    `json:"total_count"`
}

UserListResponse represents a list of users.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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