mockapi

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 6 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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