This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// model for add pet request | |
// swagger:parameters AddPet | |
type AddPetRequest struct { | |
// in: body | |
// required: true | |
Body domain.Pet `json:"body"` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swagger: "2.0" | |
// info: | |
// title: Pet API | |
// description: Spec Documentation for pet service. | |
// version: 1.0.0 | |
// | |
// schemes: | |
// - http | |
// | |
// BasePath: / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mocks | |
import ( | |
"github.com/d-vignesh/getpets/pkg/domain" | |
"github.com/google/uuid" | |
) | |
// mock for pet service | |
type PetSvc struct { | |
GetPetResp domain.Pet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app | |
import ( | |
"github.com/d-vignesh/getpets/pkg/domain" | |
"github.com/google/uuid" | |
) | |
// petSvc implements domain.PetSvc | |
type petSvc struct { | |
DB domain.PetDB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` |
NewerOlder