title: Key type for Factory implementation in Golang
body: <p>This is my first question on StackOverflow. Please be kind. :)</p>
  <p>I have a bunch of modules, each of which has a few getter functions. I am planning to unify the access of these getters by use of a factory.</p>
  <pre><code>type CommonGetterModule struct {
    cf *ContextFactory
  }
  
  func (cm *CommonGetterModule) get(key KEYTYPE, context string) interface{} {
    ctx := cm.cf.get(context)
    return ctx.get(key)
  }
  
  </code></pre>
  <p>The issue here is that the get calls implemented by each module differs by number of query parameters that together constitute the key. This would be solved best by use of named variables, but those are mysteriously absent from golang.</p>
  <pre><code>type Module1 struct {
  }
  
  func (c *Module1) get(key KEYTYPE) interface{} {
    // interpret the type of key
    keyType := determineKeyType(key)
    switch keyType {
    case keyType1: getForKeyType1(key[0], key[1])
    case keyType2: getForKeyType2(key[1])
    case keyType1: getForKeyType3(key[0], key[2])
    }
  </code></pre>
  <p>KEYTYPE can be some number of strings that can be interpreted by individual modules as part of their get methods. The expected calls can be as follows:</p>
  <pre><code>var cm CommonGetterModule
  // key1 := {userid: &quot;A10&quot;, productid: 200}
  cm.get(key1, USER_CONTEXT)
  // key2 := {userid: &quot;A10&quot;, productid: 200, expiry:&quot;2022JAN&quot;}
  cm.get(key2, USER_CONTEXT)
  // key3 := {productsymbol:&quot;ABCD&quot;}
  cm.get(key3, PRODUCT_CONTEXT)
  </code></pre>
  <p>I have narrowed down my choices of KEYTYPE implementation to these:</p>
  <ul>
  <li>map[ParameterType]ParameterValue</li>
  <li>a struct with all possible values across modules</li>
  </ul>
  <pre><code>type AllKeyTypes struct {
    userid string
    expiry string
    productid int
    productsymbol string
  }
  </code></pre>
  <ul>
  <li>some form of variadic function</li>
  </ul>
  <p>a. Which will be my best option?</p>
  <p>b. Is it even worth doing?</p>