petstore

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package petstore demonstrates a full CRUD JSON API server using r3 with GORM and PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pet

type Pet struct {
	ID        int64          `gorm:"primaryKey"                   json:"id"`
	Name      string         `gorm:"not null"                     json:"name"`
	SpeciesID int64          `gorm:"not null"                     json:"species_id"`
	Species   *Species       `gorm:"foreignKey:SpeciesID"         json:"species,omitempty"`
	Status    string         `gorm:"not null;default:'available'" json:"status"` // available, pending, sold
	Age       int            `                                    json:"age"`
	Price     float64        `                                    json:"price"`
	Tags      string         `                                    json:"tags"` // comma-separated tags for simplicity
	CreatedAt time.Time      `                                    json:"created_at"`
	UpdatedAt time.Time      `                                    json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index"                        json:"-"`
}

Pet represents a pet in the store.

type Server

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

Server is the pet store HTTP server.

func NewServer

func NewServer(db *gorm.DB) *Server

NewServer creates a new Server backed by the given gorm.DB.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type Species

type Species struct {
	ID   int64  `gorm:"primaryKey"           json:"id"`
	Name string `gorm:"uniqueIndex;not null" json:"name"`
}

Species represents a pet species (e.g. Dog, Cat, Bird).

Directories

Path Synopsis
Pet Store example server.
Pet Store example server.

Jump to

Keyboard shortcuts

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