webapi: Don't export funcs/vars unnecessarily.

This commit is contained in:
jholdstock 2023-09-11 15:22:40 +01:00 committed by Jamie Holdstock
parent b5ffecd280
commit 3967d9e24e
14 changed files with 56 additions and 56 deletions

View File

@ -44,10 +44,10 @@ func newAddressGenerator(xPub string, netParams *chaincfg.Params, lastUsedIdx ui
}, nil }, nil
} }
// NextAddress increments the last used address counter and returns a new // nextAddress increments the last used address counter and returns a new
// address. It will skip any address index which causes an ErrInvalidChild. // address. It will skip any address index which causes an ErrInvalidChild.
// Not safe for concurrent access. // Not safe for concurrent access.
func (m *addressGenerator) NextAddress() (string, uint32, error) { func (m *addressGenerator) nextAddress() (string, uint32, error) {
var key *hdkeychain.ExtendedKey var key *hdkeychain.ExtendedKey
var err error var err error

View File

@ -14,10 +14,10 @@ import (
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
// WalletStatus describes the current status of a single voting wallet. This is // walletStatus describes the current status of a single voting wallet. This is
// used by the admin.html template, and also serialized to JSON for the // used by the admin.html template, and also serialized to JSON for the
// /admin/status endpoint. // /admin/status endpoint.
type WalletStatus struct { type walletStatus struct {
Connected bool `json:"connected"` Connected bool `json:"connected"`
InfoError bool `json:"infoerror"` InfoError bool `json:"infoerror"`
DaemonConnected bool `json:"daemonconnected"` DaemonConnected bool `json:"daemonconnected"`
@ -28,10 +28,10 @@ type WalletStatus struct {
BestBlockHeight int64 `json:"bestblockheight"` BestBlockHeight int64 `json:"bestblockheight"`
} }
// DcrdStatus describes the current status of the local instance of dcrd used by // dcrdStatus describes the current status of the local instance of dcrd used by
// vspd. This is used by the admin.html template, and also serialized to JSON // vspd. This is used by the admin.html template, and also serialized to JSON
// for the /admin/status endpoint. // for the /admin/status endpoint.
type DcrdStatus struct { type dcrdStatus struct {
Host string `json:"host"` Host string `json:"host"`
Connected bool `json:"connected"` Connected bool `json:"connected"`
BestBlockError bool `json:"bestblockerror"` BestBlockError bool `json:"bestblockerror"`
@ -48,9 +48,9 @@ type searchResult struct {
MaxVoteChanges int MaxVoteChanges int
} }
func (s *Server) dcrdStatus(c *gin.Context) DcrdStatus { func (s *server) dcrdStatus(c *gin.Context) dcrdStatus {
hostname := c.MustGet(dcrdHostKey).(string) hostname := c.MustGet(dcrdHostKey).(string)
status := DcrdStatus{Host: hostname} status := dcrdStatus{Host: hostname}
dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC) dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC)
dcrdErr := c.MustGet(dcrdErrorKey) dcrdErr := c.MustGet(dcrdErrorKey)
@ -73,13 +73,13 @@ func (s *Server) dcrdStatus(c *gin.Context) DcrdStatus {
return status return status
} }
func (s *Server) walletStatus(c *gin.Context) map[string]WalletStatus { func (s *server) walletStatus(c *gin.Context) map[string]walletStatus {
walletClients := c.MustGet(walletsKey).([]*rpc.WalletRPC) walletClients := c.MustGet(walletsKey).([]*rpc.WalletRPC)
failedWalletClients := c.MustGet(failedWalletsKey).([]string) failedWalletClients := c.MustGet(failedWalletsKey).([]string)
walletStatus := make(map[string]WalletStatus) status := make(map[string]walletStatus)
for _, v := range walletClients { for _, v := range walletClients {
ws := WalletStatus{Connected: true} ws := walletStatus{Connected: true}
walletInfo, err := v.WalletInfo() walletInfo, err := v.WalletInfo()
if err != nil { if err != nil {
@ -100,18 +100,18 @@ func (s *Server) walletStatus(c *gin.Context) map[string]WalletStatus {
ws.BestBlockHeight = height ws.BestBlockHeight = height
} }
walletStatus[v.String()] = ws status[v.String()] = ws
} }
for _, v := range failedWalletClients { for _, v := range failedWalletClients {
ws := WalletStatus{Connected: false} ws := walletStatus{Connected: false}
walletStatus[v] = ws status[v] = ws
} }
return walletStatus return status
} }
// statusJSON is the handler for "GET /admin/status". It returns a JSON object // statusJSON is the handler for "GET /admin/status". It returns a JSON object
// describing the current status of voting wallets. // describing the current status of voting wallets.
func (s *Server) statusJSON(c *gin.Context) { func (s *server) statusJSON(c *gin.Context) {
httpStatus := http.StatusOK httpStatus := http.StatusOK
wallets := s.walletStatus(c) wallets := s.walletStatus(c)
@ -143,7 +143,7 @@ func (s *Server) statusJSON(c *gin.Context) {
} }
// adminPage is the handler for "GET /admin". // adminPage is the handler for "GET /admin".
func (s *Server) adminPage(c *gin.Context) { func (s *server) adminPage(c *gin.Context) {
c.HTML(http.StatusOK, "admin.html", gin.H{ c.HTML(http.StatusOK, "admin.html", gin.H{
"WebApiCache": s.cache.getData(), "WebApiCache": s.cache.getData(),
"WebApiCfg": s.cfg, "WebApiCfg": s.cfg,
@ -154,7 +154,7 @@ func (s *Server) adminPage(c *gin.Context) {
// ticketSearch is the handler for "POST /admin/ticket". The hash param will be // ticketSearch is the handler for "POST /admin/ticket". The hash param will be
// used to retrieve a ticket from the database. // used to retrieve a ticket from the database.
func (s *Server) ticketSearch(c *gin.Context) { func (s *server) ticketSearch(c *gin.Context) {
hash := c.PostForm("hash") hash := c.PostForm("hash")
ticket, found, err := s.db.GetTicketByHash(hash) ticket, found, err := s.db.GetTicketByHash(hash)
@ -227,7 +227,7 @@ func (s *Server) ticketSearch(c *gin.Context) {
// adminLogin is the handler for "POST /admin". If a valid password is provided, // adminLogin is the handler for "POST /admin". If a valid password is provided,
// the current session will be authenticated as an admin. // the current session will be authenticated as an admin.
func (s *Server) adminLogin(c *gin.Context) { func (s *server) adminLogin(c *gin.Context) {
password := c.PostForm("password") password := c.PostForm("password")
if password != s.cfg.AdminPass { if password != s.cfg.AdminPass {
@ -245,13 +245,13 @@ func (s *Server) adminLogin(c *gin.Context) {
// adminLogout is the handler for "POST /admin/logout". The current session will // adminLogout is the handler for "POST /admin/logout". The current session will
// have its admin authentication removed. // have its admin authentication removed.
func (s *Server) adminLogout(c *gin.Context) { func (s *server) adminLogout(c *gin.Context) {
s.setAdminStatus(nil, c) s.setAdminStatus(nil, c)
} }
// downloadDatabaseBackup is the handler for "GET /backup". A binary // downloadDatabaseBackup is the handler for "GET /backup". A binary
// representation of the whole database is generated and returned to the client. // representation of the whole database is generated and returned to the client.
func (s *Server) downloadDatabaseBackup(c *gin.Context) { func (s *server) downloadDatabaseBackup(c *gin.Context) {
err := s.db.BackupDB(c.Writer) err := s.db.BackupDB(c.Writer)
if err != nil { if err != nil {
s.log.Errorf("Error backing up database: %v", err) s.log.Errorf("Error backing up database: %v", err)
@ -263,7 +263,7 @@ func (s *Server) downloadDatabaseBackup(c *gin.Context) {
// setAdminStatus stores the authentication status of the current session and // setAdminStatus stores the authentication status of the current session and
// redirects the client to GET /admin. // redirects the client to GET /admin.
func (s *Server) setAdminStatus(admin any, c *gin.Context) { func (s *server) setAdminStatus(admin any, c *gin.Context) {
session := c.MustGet(sessionKey).(*sessions.Session) session := c.MustGet(sessionKey).(*sessions.Session)
session.Values["admin"] = admin session.Values["admin"] = admin
err := session.Save(c.Request, c.Writer) err := session.Save(c.Request, c.Writer)

View File

@ -24,11 +24,11 @@ var addrMtx sync.Mutex
// the last used address index in the database. In order to maintain consistency // the last used address index in the database. In order to maintain consistency
// between the internal counter of address generator and the database, this func // between the internal counter of address generator and the database, this func
// uses a mutex to ensure it is not run concurrently. // uses a mutex to ensure it is not run concurrently.
func (s *Server) getNewFeeAddress() (string, uint32, error) { func (s *server) getNewFeeAddress() (string, uint32, error) {
addrMtx.Lock() addrMtx.Lock()
defer addrMtx.Unlock() defer addrMtx.Unlock()
addr, idx, err := s.addrGen.NextAddress() addr, idx, err := s.addrGen.nextAddress()
if err != nil { if err != nil {
return "", 0, err return "", 0, err
} }
@ -43,7 +43,7 @@ func (s *Server) getNewFeeAddress() (string, uint32, error) {
// getCurrentFee returns the minimum fee amount a client should pay in order to // getCurrentFee returns the minimum fee amount a client should pay in order to
// register a ticket with the VSP at the current block height. // register a ticket with the VSP at the current block height.
func (s *Server) getCurrentFee(dcrdClient *rpc.DcrdRPC) (dcrutil.Amount, error) { func (s *server) getCurrentFee(dcrdClient *rpc.DcrdRPC) (dcrutil.Amount, error) {
bestBlock, err := dcrdClient.GetBestBlockHeader() bestBlock, err := dcrdClient.GetBestBlockHeader()
if err != nil { if err != nil {
return 0, err return 0, err
@ -70,7 +70,7 @@ func (s *Server) getCurrentFee(dcrdClient *rpc.DcrdRPC) (dcrutil.Amount, error)
} }
// feeAddress is the handler for "POST /api/v3/feeaddress". // feeAddress is the handler for "POST /api/v3/feeaddress".
func (s *Server) feeAddress(c *gin.Context) { func (s *server) feeAddress(c *gin.Context) {
const funcName = "feeAddress" const funcName = "feeAddress"

View File

@ -172,7 +172,7 @@ func validateTicketHash(hash string) error {
// canTicketVote checks determines whether a ticket is able to vote at some // canTicketVote checks determines whether a ticket is able to vote at some
// point in the future by checking that it is currently either in the mempool, // point in the future by checking that it is currently either in the mempool,
// immature or live. // immature or live.
func canTicketVote(rawTx *dcrdtypes.TxRawResult, dcrdClient Node, netParams *chaincfg.Params) (bool, error) { func canTicketVote(rawTx *dcrdtypes.TxRawResult, dcrdClient node, netParams *chaincfg.Params) (bool, error) {
// Tickets which have more than (TicketMaturity+TicketExpiry+1) // Tickets which have more than (TicketMaturity+TicketExpiry+1)
// confirmations are too old to vote. // confirmations are too old to vote.

View File

@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func (s *Server) homepage(c *gin.Context) { func (s *server) homepage(c *gin.Context) {
c.HTML(http.StatusOK, "homepage.html", gin.H{ c.HTML(http.StatusOK, "homepage.html", gin.H{
"WebApiCache": s.cache.getData(), "WebApiCache": s.cache.getData(),
"WebApiCfg": s.cfg, "WebApiCfg": s.cfg,

View File

@ -63,7 +63,7 @@ func rateLimit(limit rate.Limit, limitExceeded gin.HandlerFunc) gin.HandlerFunc
// withSession middleware adds a gorilla session to the request context for // withSession middleware adds a gorilla session to the request context for
// downstream handlers to make use of. Sessions are used by admin pages to // downstream handlers to make use of. Sessions are used by admin pages to
// maintain authentication status. // maintain authentication status.
func (s *Server) withSession(store *sessions.CookieStore) gin.HandlerFunc { func (s *server) withSession(store *sessions.CookieStore) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
session, err := store.Get(c.Request, "vspd-session") session, err := store.Get(c.Request, "vspd-session")
if err != nil { if err != nil {
@ -95,7 +95,7 @@ func (s *Server) withSession(store *sessions.CookieStore) gin.HandlerFunc {
// requireAdmin will only allow the request to proceed if the current session is // requireAdmin will only allow the request to proceed if the current session is
// authenticated as an admin, otherwise it will render the login template. // authenticated as an admin, otherwise it will render the login template.
func (s *Server) requireAdmin(c *gin.Context) { func (s *server) requireAdmin(c *gin.Context) {
session := c.MustGet(sessionKey).(*sessions.Session) session := c.MustGet(sessionKey).(*sessions.Session)
admin := session.Values["admin"] admin := session.Values["admin"]
@ -111,7 +111,7 @@ func (s *Server) requireAdmin(c *gin.Context) {
// withDcrdClient middleware adds a dcrd client to the request context for // withDcrdClient middleware adds a dcrd client to the request context for
// downstream handlers to make use of. // downstream handlers to make use of.
func (s *Server) withDcrdClient(dcrd rpc.DcrdConnect) gin.HandlerFunc { func (s *server) withDcrdClient(dcrd rpc.DcrdConnect) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
client, hostname, err := dcrd.Client() client, hostname, err := dcrd.Client()
// Don't handle the error here, add it to the context and let downstream // Don't handle the error here, add it to the context and let downstream
@ -125,7 +125,7 @@ func (s *Server) withDcrdClient(dcrd rpc.DcrdConnect) gin.HandlerFunc {
// withWalletClients middleware attempts to add voting wallet clients to the // withWalletClients middleware attempts to add voting wallet clients to the
// request context for downstream handlers to make use of. Downstream handlers // request context for downstream handlers to make use of. Downstream handlers
// must handle the case where no wallet clients are connected. // must handle the case where no wallet clients are connected.
func (s *Server) withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc { func (s *server) withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
clients, failedConnections := wallets.Clients() clients, failedConnections := wallets.Clients()
if len(clients) == 0 { if len(clients) == 0 {
@ -151,7 +151,7 @@ func drainAndReplaceBody(req *http.Request) ([]byte, error) {
return reqBytes, nil return reqBytes, nil
} }
func (s *Server) vspMustBeOpen(c *gin.Context) { func (s *server) vspMustBeOpen(c *gin.Context) {
if s.cfg.VspClosed { if s.cfg.VspClosed {
s.sendError(types.ErrVspClosed, c) s.sendError(types.ErrVspClosed, c)
return return
@ -163,7 +163,7 @@ func (s *Server) vspMustBeOpen(c *gin.Context) {
// Ticket hash, ticket hex, and parent hex are parsed from the request body and // Ticket hash, ticket hex, and parent hex are parsed from the request body and
// validated. They are broadcast to the network using SendRawTransaction if dcrd // validated. They are broadcast to the network using SendRawTransaction if dcrd
// is not aware of them. // is not aware of them.
func (s *Server) broadcastTicket(c *gin.Context) { func (s *server) broadcastTicket(c *gin.Context) {
const funcName = "broadcastTicket" const funcName = "broadcastTicket"
// Read request bytes. // Read request bytes.
@ -304,7 +304,7 @@ func (s *Server) broadcastTicket(c *gin.Context) {
// does not contain the request body signed with the commitment address. // does not contain the request body signed with the commitment address.
// Ticket information is added to the request context for downstream handlers to // Ticket information is added to the request context for downstream handlers to
// use. // use.
func (s *Server) vspAuth(c *gin.Context) { func (s *server) vspAuth(c *gin.Context) {
const funcName = "vspAuth" const funcName = "vspAuth"
// Read request bytes. // Read request bytes.

View File

@ -21,7 +21,7 @@ import (
) )
// payFee is the handler for "POST /api/v3/payfee". // payFee is the handler for "POST /api/v3/payfee".
func (s *Server) payFee(c *gin.Context) { func (s *server) payFee(c *gin.Context) {
const funcName = "payFee" const funcName = "payFee"
// Get values which have been added to context by middleware. // Get values which have been added to context by middleware.

View File

@ -26,11 +26,11 @@ var (
slash = []byte("/") slash = []byte("/")
) )
// Recovery returns a middleware that recovers from any panics which occur in // recovery returns a middleware that recovers from any panics which occur in
// request handlers. It logs the panic, a stack trace, and the full request // request handlers. It logs the panic, a stack trace, and the full request
// details. It also ensure the client receives a 500 response rather than no // details. It also ensure the client receives a 500 response rather than no
// response at all. // response at all.
func Recovery(log slog.Logger) gin.HandlerFunc { func recovery(log slog.Logger) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {

View File

@ -17,21 +17,21 @@ import (
) )
// Ensure that Node is satisfied by *rpc.DcrdRPC. // Ensure that Node is satisfied by *rpc.DcrdRPC.
var _ Node = (*rpc.DcrdRPC)(nil) var _ node = (*rpc.DcrdRPC)(nil)
// Node is satisfied by *rpc.DcrdRPC and retrieves data from the blockchain. // node is satisfied by *rpc.DcrdRPC and retrieves data from the blockchain.
type Node interface { type node interface {
ExistsLiveTicket(ticketHash string) (bool, error) ExistsLiveTicket(ticketHash string) (bool, error)
GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, error) GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, error)
} }
// setAltSignAddr is the handler for "POST /api/v3/setaltsignaddr". // setAltSignAddr is the handler for "POST /api/v3/setaltsignaddr".
func (s *Server) setAltSignAddr(c *gin.Context) { func (s *server) setAltSignAddr(c *gin.Context) {
const funcName = "setAltSignAddr" const funcName = "setAltSignAddr"
// Get values which have been added to context by middleware. // Get values which have been added to context by middleware.
dcrdClient := c.MustGet(dcrdKey).(Node) dcrdClient := c.MustGet(dcrdKey).(node)
dcrdErr := c.MustGet(dcrdErrorKey) dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil { if dcrdErr != nil {
s.log.Errorf("%s: Could not get dcrd client: %v", funcName, dcrdErr.(error)) s.log.Errorf("%s: Could not get dcrd client: %v", funcName, dcrdErr.(error))

View File

@ -39,7 +39,7 @@ var (
seededRand = rand.New(rand.NewSource(time.Now().UnixNano())) seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
feeXPub = "feexpub" feeXPub = "feexpub"
maxVoteChangeRecords = 3 maxVoteChangeRecords = 3
api *Server api *server
) )
// randBytes returns a byte slice of size n filled with random bytes. // randBytes returns a byte slice of size n filled with random bytes.
@ -84,7 +84,7 @@ func TestMain(m *testing.M) {
panic(fmt.Errorf("error opening test database: %w", err)) panic(fmt.Errorf("error opening test database: %w", err))
} }
api = &Server{ api = &server{
cfg: cfg, cfg: cfg,
signPrivKey: signPrivKey, signPrivKey: signPrivKey,
db: db, db: db,
@ -112,7 +112,7 @@ func randString(length int, charset string) string {
} }
// Ensure that testNode satisfies Node. // Ensure that testNode satisfies Node.
var _ Node = (*testNode)(nil) var _ node = (*testNode)(nil)
type testNode struct { type testNode struct {
getRawTransaction *dcrdtypes.TxRawResult getRawTransaction *dcrdtypes.TxRawResult

View File

@ -17,7 +17,7 @@ import (
) )
// setVoteChoices is the handler for "POST /api/v3/setvotechoices". // setVoteChoices is the handler for "POST /api/v3/setvotechoices".
func (s *Server) setVoteChoices(c *gin.Context) { func (s *server) setVoteChoices(c *gin.Context) {
const funcName = "setVoteChoices" const funcName = "setVoteChoices"
// Get values which have been added to context by middleware. // Get values which have been added to context by middleware.

View File

@ -14,7 +14,7 @@ import (
) )
// ticketStatus is the handler for "POST /api/v3/ticketstatus". // ticketStatus is the handler for "POST /api/v3/ticketstatus".
func (s *Server) ticketStatus(c *gin.Context) { func (s *server) ticketStatus(c *gin.Context) {
const funcName = "ticketStatus" const funcName = "ticketStatus"
// Get values which have been added to context by middleware. // Get values which have been added to context by middleware.

View File

@ -13,7 +13,7 @@ import (
) )
// vspInfo is the handler for "GET /api/v3/vspinfo". // vspInfo is the handler for "GET /api/v3/vspinfo".
func (s *Server) vspInfo(c *gin.Context) { func (s *server) vspInfo(c *gin.Context) {
cachedStats := s.cache.getData() cachedStats := s.cache.getData()
s.sendJSONResponse(types.VspInfoResponse{ s.sendJSONResponse(types.VspInfoResponse{
APIVersions: []int64{3}, APIVersions: []int64{3},

View File

@ -65,7 +65,7 @@ const (
commitmentAddressKey = "CommitmentAddress" commitmentAddressKey = "CommitmentAddress"
) )
type Server struct { type server struct {
cfg Config cfg Config
db *database.VspDatabase db *database.VspDatabase
log slog.Logger log slog.Logger
@ -79,7 +79,7 @@ func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGro
listen string, vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect, listen string, vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect,
wallets rpc.WalletConnect, config Config) error { wallets rpc.WalletConnect, config Config) error {
s := &Server{ s := &server{
cfg: config, cfg: config,
db: vdb, db: vdb,
log: log, log: log,
@ -191,7 +191,7 @@ func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGro
return nil return nil
} }
func (s *Server) router(cookieSecret []byte, dcrd rpc.DcrdConnect, wallets rpc.WalletConnect) *gin.Engine { func (s *server) router(cookieSecret []byte, dcrd rpc.DcrdConnect, wallets rpc.WalletConnect) *gin.Engine {
// With release mode enabled, gin will only read template files once and cache them. // With release mode enabled, gin will only read template files once and cache them.
// With release mode disabled, templates will be reloaded on the fly. // With release mode disabled, templates will be reloaded on the fly.
if !s.cfg.Debug { if !s.cfg.Debug {
@ -218,7 +218,7 @@ func (s *Server) router(cookieSecret []byte, dcrd rpc.DcrdConnect, wallets rpc.W
// Recovery middleware handles any go panics generated while processing web // Recovery middleware handles any go panics generated while processing web
// requests. Ensures a 500 response is sent to the client rather than // requests. Ensures a 500 response is sent to the client rather than
// sending no response at all. // sending no response at all.
router.Use(Recovery(s.log)) router.Use(recovery(s.log))
if s.cfg.Debug { if s.cfg.Debug {
// Logger middleware outputs very detailed logging of webserver requests // Logger middleware outputs very detailed logging of webserver requests
@ -283,7 +283,7 @@ func (s *Server) router(cookieSecret []byte, dcrd rpc.DcrdConnect, wallets rpc.W
// sendJSONResponse serializes the provided response, signs it, and sends the // sendJSONResponse serializes the provided response, signs it, and sends the
// response to the client with a 200 OK status. Returns the seralized response // response to the client with a 200 OK status. Returns the seralized response
// and the signature. // and the signature.
func (s *Server) sendJSONResponse(resp any, c *gin.Context) (string, string) { func (s *server) sendJSONResponse(resp any, c *gin.Context) (string, string) {
dec, err := json.Marshal(resp) dec, err := json.Marshal(resp)
if err != nil { if err != nil {
s.log.Errorf("JSON marshal error: %v", err) s.log.Errorf("JSON marshal error: %v", err)
@ -302,14 +302,14 @@ func (s *Server) sendJSONResponse(resp any, c *gin.Context) (string, string) {
// sendError sends an error response with the provided error code and the // sendError sends an error response with the provided error code and the
// default message for that code. // default message for that code.
func (s *Server) sendError(e types.ErrorCode, c *gin.Context) { func (s *server) sendError(e types.ErrorCode, c *gin.Context) {
msg := e.DefaultMessage() msg := e.DefaultMessage()
s.sendErrorWithMsg(msg, e, c) s.sendErrorWithMsg(msg, e, c)
} }
// sendErrorWithMsg sends an error response with the provided error code and // sendErrorWithMsg sends an error response with the provided error code and
// message. // message.
func (s *Server) sendErrorWithMsg(msg string, e types.ErrorCode, c *gin.Context) { func (s *server) sendErrorWithMsg(msg string, e types.ErrorCode, c *gin.Context) {
status := e.HTTPStatus() status := e.HTTPStatus()
resp := types.ErrorResponse{ resp := types.ErrorResponse{