It works temporarily, but then I have to manually update each file that imports + exports the methods, it won't "just work" with new versions of the library that gets imported, right?
On Wed, Sep 23, 2020 at 11:59 AM Jason Phillips <jasonryanphill...@gmail.com> wrote: > Did you try your own suggestion? It seems to work fine: > https://play.golang.org/p/KVo5COKj2ii > > On Wednesday, September 23, 2020 at 1:46:05 PM UTC-4 > al...@channelmeter.com wrote: > >> Using node.js, we might have this: >> >> const z = new Z(); >> exports.z = z >> >> and then in another file we can import >> >> import {z} from '../z' >> >> with Golang, I am trying to do something similar: >> >> package log >> >> import Logger "github.com/foo/bar/logger" >> >> // create an instance >> var log = Logger.create() >> >> // export the methods >> var Info = log.Info >> var Warn = log.Warn >> var Error = log.Error >> >> and then we import it like >> >> import "github.com/a/b/log" >> >> func init(){ >> log.Info("something") >> log.Warn("something") >> } >> >> /// =========== >> >> basically what I am asking is if there is a way to create an instance and >> access it's methods - so that in my code I don't have to do: >> >> log.log.Info() >> >> but instead I can do: >> >> log.Info() >> >> hope the question makes sense. >> >> >> >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/d2f2125f-9260-4268-ac31-cfe738dc3f5en%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/d2f2125f-9260-4268-ac31-cfe738dc3f5en%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAL6oN2eu48tPCH%3DWoLtwCJt5OErC0L33%2BWfL_cXmLBRz89VACQ%40mail.gmail.com.