Last active
July 8, 2024 02:51
-
-
Save ahmadmilzam/d383d9e524004e1c0257b00b63d7dc99 to your computer and use it in GitHub Desktop.
Code snippet
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 ( | |
"encoding/json" | |
"net/http" | |
"sync" | |
"time" | |
"github.com/gorilla/mux" | |
) | |
// TODO: Implement in-memory store | |
type Payment struct { | |
ID string `json:"id"` // self generated | |
ReferenceID string `json:"reference_id"` // client generated | |
Amount int `json:"amount"` | |
Timestamp time.Time `json:"timestamp"` | |
PartnerReferenceID string `json:"partner_reference_id"`// partner generated | |
Status string `json:"status"` | |
} | |
// TODO: Implement createPaymentHandler | |
func createPaymentHandler(w http.ResponseWriter, r *http.Request) {...} | |
func main() { | |
r := mux.NewRouter() | |
r.HandleFunc("/payments", createPaymentHandler).Methods(http.MethodPost) | |
http.ListenAndServe(":8080", r) | |
} | |
// TODO: Write unit tests for createPaymentHandler | |
// Helper function to generate a unique ID for each payment | |
func generateID() string { | |
// Implement a unique ID generation logic | |
return "some-unique-id" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment