Answer the question
In order to leave comments, you need to log in
Is it possible to write a Go function that extends a third-party package?
There is a certain package:
ext_api.go
package ext_api
type Data struct {
a string
b int
}
func Create() Data {
d := Data{"text", 10}
return d
}
func (d *Data) PrintData() {
println(d.a)
}
package main
import "ext_api"
func main() {
data := ext_api.Create()
data.PrintData()
}
func (d *Data) PrintDataEx() {
println(d.a, " ", d.b)
}
Answer the question
In order to leave comments, you need to log in
Option 1 - Alias:
type MyType ext_api.Data
func (m *MyType) PrintDataEx() {...}
type MyStruct struct {
*ext_api.Data
}
func (m *MyStruct) Method() {...}
m := &MyStruct{...}
m.Method()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question