What I would like to do is as follows. I have an application code (say, MyApp), one package (perhaps) from a third party, and the other from gccgo. They are particularly golang.org/sys/unix and syscall, respectively.
MyApp tries to assign a syscall.Timespec variable to an unix.Timespec variable. That is mismatch when I use syscall from gccgo while it is not when the syscall is from Gc.
I would like to avoid changing the two libraries. I would like to make a change to MyApp. However, the patch will not go to the upstream of MyApp. I, or my employer, should maintain the patch locally. That says if the git repo of MyApp is updated, we would need to pull it again and apply another patch to it.
In that sense, I would like to try to minimize the efforts for the future maintenance.
The mismatch itself is as follows, if I simplify:
// example.go
package main
import "fmt"
type aliased_int int
type SrcStruct struct {
x aliased_int
}
type DstStruct struct {
x int
}
func main() {
src := SrcStruct{x: 30}
dst := DstStruct(src)
fmt.Println(dst.x)
}
The code above caused a compile error due to the "x aliased_int" line. If it were "x int," the code is compiled successfully.
If this were a C++ application and libraries, I would define a type-casting operator overloading from SrcStruct to DstStruct. (%p.s. this won't work because C++ does not allow type-casting operator overloading as a global function. However, I wanted to know such a solution is available in Go.)
I am not sure if I could do the same in Go. (i.e. defining a custom type-casting operator as a global function or so) If not, what is the best for this situation when it comes to Go programming?
%P.S.
Michael Hampton kindly pointed out that gccgo's Timespec is different from Google Go compiler, Gc's Timespec. The difference is, however, gccgo uses an alias to int64 such as Timespec_sec_t or Timespec_nsec_t.
Gccgo's Timespec is defined in Gccgo's package. Gc's Timespec is included in MyApp's source tree. MyApp assumes that Timespec is the same as Gc defined. I would like only touch MyApp code minimally.