Hacker symbol

January 24, 2020 ~ 1 min read

Interface signature for Function

I was playing around with how to do function signatures with an interface just to see if could be done and I came up with this:

// Using an interface instead of a func(string, string) declaration
// because other chains might have different requirements
var currencyRequestMap = map[string]interface{}{
    "rin": newEthRequest,
    "gor": newEthRequest,
    "bnb": newCosmosRequest,
    "cos": newCosmosRequest,

func (k *Currency) sendTransaction(currencyIdentifier string, txHex string) error {

    var request *URLRequest
    var err error
    switch currencyIdentifier {
    case "rin", "gor":
        request, err = currencyRequestMap["rin"].(func(string, []string) (*URLRequest, error))(k.rpcURL, []string{txHex})
    case "bnb", "cos":
        request, err = currencyRequestMa

In the end it is just easier to make the switch to call the function directly, but it was a fun experiment. 😊

Sebastian Bolaños

Hi, I'm Sebastian. I'm a software developer from Costa Rica. You can follow me on Twitter. I enjoy working on trustless systems.