mockapi

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 6 Imported by: 2

README

Mock API

A minimal mock API implementation used in runnable examples on pkg.go.dev.

This package simulates common API patterns like:

  • Single and bulk item fetching
  • Pagination
  • Network delay simulation
  • Realistic error scenarios

The package is intentionally kept public to enable running and experimenting with examples in the Go Playground.

Documentation

Overview

Package mockapi provides a very basic mock API for examples and demos. It's intentionally kept public to enable running and experimenting with examples in the Go Playground. The implementation is naive and uses full scan for all operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(ctx context.Context, url string) ([]byte, error)

DownloadFile simulates a file download. It returns the whole content as []byte.

func GetDepartments

func GetDepartments() ([]string, error)

func SaveUser

func SaveUser(ctx context.Context, user *User) error

SaveUser saves a user.

Types

type User

type User struct {
	ID         int
	Name       string
	Age        int
	Department string
	IsActive   bool
}

func GetUser

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

GetUser returns a user by ID.

func GetUsers

func GetUsers(ctx context.Context, ids []int) ([]*User, error)

GetUsers returns a list of users by IDs. If a user is not found, nil is returned in the corresponding position.

func ListUsers

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

ListUsers returns a paginated list of users optionally filtered by department.

type UserQuery

type UserQuery struct {
	Department string
	Page       int
}

Jump to

Keyboard shortcuts

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