title: In golang how to get an instance of interface by name in config file
body: <p>I want to know how can I inject dependency flexibly in golang just like java spring, Which is if I want to change a instance of an interface all I have to do is just to change some config file.</p>
  
  <p>First I want to find some function like <strong>getTypeByName()</strong>, so I can just give a struct name like "mypkg.structName" in config file and load that struct by the function, but it seems that there is no such function in golang.</p>
  
  <p>And now the most doable way i can think is to create a loader model to generate a <a href="https://play.golang.org/p/igmssSD9k2" rel="nofollow noreferrer">struct register file</a> to load all custom struct.</p>
  
  <p>But I want to know is there have a easier way to do that, all is there some golang-style way to implement this flexibility? </p>