gomock

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gomock provides a simple in-memory JSON-based mock server for testing and development. It allows creating a lightweight HTTP server that can handle CRUD operations on JSON collections.

The server supports the following HTTP methods:

  • GET: Retrieve all items in a collection or a specific item by ID
  • POST: Create a new item in a collection
  • PUT: Update an existing item in a collection
  • DELETE: Remove an item from a collection

Usage:

go run main.go -db=mydata.json -port=8080

Flags:

-db string
  	Path to the JSON database file (default "db.json")
-port int
  	Port number for the server to listen on (default 3000)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run() error

Run starts the mock server with command-line configurable options.

Flags:

  • db: JSON database file path (default: "db.json")
  • port: Server listening port (default: 3000)

Returns:

  • error: Any error encountered while starting the server

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the mock JSON server with data management capabilities. It maintains an in-memory collection of data and provides methods to interact with it.

func NewServer

func NewServer(filename string) (*Server, error)

NewServer initializes a new Server instance by loading data from a JSON file.

Parameters:

  • filename: Path to the JSON database file

Returns:

  • *Server: Configured server instance
  • error: Any error encountered during initialization

Jump to

Keyboard shortcuts

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