Skip to content

Instantly share code, notes, and snippets.

View d-vignesh's full-sized avatar

vignesh d-vignesh

  • Bangalore
View GitHub Profile
@d-vignesh
d-vignesh / redocmiddleware.go
Last active March 5, 2023 12:46
redoc middleware to serve our specification over html
opts := redocmiddleware.RedocOpts{Path: "docs", SpecURL: "swagger.json"}
docsHandler := redocmiddleware.Redoc(opts, nil)
r.Handle("/docs", docsHandler)
r.Get("/swagger.json", func(w http.ResponseWriter, r *http.Request) {
spec, err := ioutil.ReadFile("docs/swagger.json")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
@d-vignesh
d-vignesh / AddPetRequestPayload.go
Created March 5, 2023 10:59
AddPet request payload schema
// model for add pet request
// swagger:parameters AddPet
type AddPetRequest struct {
// in: body
// required: true
Body domain.Pet `json:"body"`
}
@d-vignesh
d-vignesh / AddPetResponses.go
Last active March 5, 2023 10:50
Response schemas for AddPet endpoint
// model for error response
// swagger:response ErrorResponse
type ErrorResponse struct {
// in:body
Body struct {
Msg string `json:"message"`
} `json:"body"`
}
// model for add success response without data
@d-vignesh
d-vignesh / docs.json
Last active March 5, 2023 07:50
Swagger Meta
// swagger: "2.0"
// info:
// title: Pet API
// description: Spec Documentation for pet service.
// version: 1.0.0
//
// schemes:
// - http
//
// BasePath: /
package main
import (
"fmt"
"net/http"
"os"
"github.com/d-vignesh/getpets/mocks"
"github.com/d-vignesh/getpets/pkg/app"
"github.com/d-vignesh/getpets/pkg/db"
package mocks
import (
"github.com/d-vignesh/getpets/pkg/domain"
"github.com/google/uuid"
)
// mock for pet service
type PetSvc struct {
GetPetResp domain.Pet
package db
import (
"context"
"os"
"github.com/d-vignesh/getpets/pkg/domain"
"github.com/google/uuid"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
package db
import (
"github.com/d-vignesh/getpets/pkg/domain"
"github.com/google/uuid"
"github.com/pkg/errors"
)
// inMemStore implements domain.PetDB with an memory storage
type inMemStore struct {
package app
import (
"github.com/d-vignesh/getpets/pkg/domain"
"github.com/google/uuid"
)
// petSvc implements domain.PetSvc
type petSvc struct {
DB domain.PetDB
package domain
import (
"github.com/google/uuid"
)
type Pet struct {
ID uuid.UUID `json:"id" bson:"id,omitempty"`
Category string `json:"category" bson:"category,omitempty"`
Breed string `json:"breed" bson:"breed,omitempty"`