Skip to content

Commit

Permalink
dedupe template function
Browse files Browse the repository at this point in the history
  • Loading branch information
potterbm-cb committed Oct 18, 2024
1 parent d6435a4 commit 7511949
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 122 deletions.
10 changes: 0 additions & 10 deletions server/api_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ func (c *AccountAPIController) AccountBalance(w http.ResponseWriter, r *http.Req
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *AccountAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// AccountCoins - Get an Account's Unspent Coins
func (c *AccountAPIController) AccountCoins(w http.ResponseWriter, r *http.Request) {
accountCoinsRequest := &types.AccountCoinsRequest{}
Expand Down
10 changes: 0 additions & 10 deletions server/api_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ func (c *BlockAPIController) Block(w http.ResponseWriter, r *http.Request) {
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *BlockAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// BlockTransaction - Get a Block Transaction
func (c *BlockAPIController) BlockTransaction(w http.ResponseWriter, r *http.Request) {
blockTransactionRequest := &types.BlockTransactionRequest{}
Expand Down
70 changes: 0 additions & 70 deletions server/api_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ func (c *ConstructionAPIController) ConstructionCombine(w http.ResponseWriter, r
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionDerive - Derive an AccountIdentifier from a PublicKey
func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r *http.Request) {
constructionDeriveRequest := &types.ConstructionDeriveRequest{}
Expand Down Expand Up @@ -187,16 +177,6 @@ func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionHash - Get the Hash of a Signed Transaction
func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *http.Request) {
constructionHashRequest := &types.ConstructionHashRequest{}
Expand Down Expand Up @@ -230,16 +210,6 @@ func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *h
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionMetadata - Get Metadata for Transaction Construction
func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter, r *http.Request) {
constructionMetadataRequest := &types.ConstructionMetadataRequest{}
Expand Down Expand Up @@ -273,16 +243,6 @@ func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter,
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionParse - Parse a Transaction
func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *http.Request) {
constructionParseRequest := &types.ConstructionParseRequest{}
Expand Down Expand Up @@ -316,16 +276,6 @@ func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionPayloads - Generate an Unsigned Transaction and Signing Payloads
func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter, r *http.Request) {
constructionPayloadsRequest := &types.ConstructionPayloadsRequest{}
Expand Down Expand Up @@ -359,16 +309,6 @@ func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter,
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionPreprocess - Create a Request to Fetch Metadata
func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter, r *http.Request) {
constructionPreprocessRequest := &types.ConstructionPreprocessRequest{}
Expand Down Expand Up @@ -402,16 +342,6 @@ func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *ConstructionAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// ConstructionSubmit - Submit a Signed Transaction
func (c *ConstructionAPIController) ConstructionSubmit(w http.ResponseWriter, r *http.Request) {
constructionSubmitRequest := &types.ConstructionSubmitRequest{}
Expand Down
10 changes: 0 additions & 10 deletions server/api_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ func (c *MempoolAPIController) Mempool(w http.ResponseWriter, r *http.Request) {
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *MempoolAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// MempoolTransaction - Get a Mempool Transaction
func (c *MempoolAPIController) MempoolTransaction(w http.ResponseWriter, r *http.Request) {
mempoolTransactionRequest := &types.MempoolTransactionRequest{}
Expand Down
20 changes: 0 additions & 20 deletions server/api_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ func (c *NetworkAPIController) NetworkList(w http.ResponseWriter, r *http.Reques
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *NetworkAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// NetworkOptions - Get Network Options
func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Request) {
networkRequest := &types.NetworkRequest{}
Expand Down Expand Up @@ -151,16 +141,6 @@ func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Req
EncodeJSONResponse(result, http.StatusOK, w)
}

func (c *NetworkAPIController) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()

if c.contextFromRequest != nil {
ctx = c.contextFromRequest(r)
}

return ctx
}

// NetworkStatus - Get Network Status
func (c *NetworkAPIController) NetworkStatus(w http.ResponseWriter, r *http.Request) {
networkRequest := &types.NetworkRequest{}
Expand Down
4 changes: 2 additions & 2 deletions templates/server/controller-api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *{{classname}}Controller) Routes() Routes {
c.{{operationId}},
},{{/operation}}{{/operations}}
}
}{{#operations}}{{#operation}}
}

func (c *{{classname}}Controller) ContextFromRequest(r *http.Request) context.Context {
ctx := r.Context()
Expand All @@ -51,7 +51,7 @@ func (c *{{classname}}Controller) ContextFromRequest(r *http.Request) context.Co
}

return ctx
}
}{{#operations}}{{#operation}}

// {{nickname}} - {{{summary}}}
func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Request) { {{#allParams}}{{#isHeaderParam}}
Expand Down

0 comments on commit 7511949

Please sign in to comment.