mockapi

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mockapi provides a very basic mock API client for examples and demos. Unfortunately it must live outside the internal folder to be accessible from runnable examples and go playground.

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