How to create some function in GO Lang without care about DATA TYPE

Viewed 34

How to create some reusable function in GO Lang without care about DATA TYPE, Especially for the Struct in GO Lang?

for example in JS like this:

function foo(param1, param2) {
  // some Stuff must be here using any data type, especially for the struct from param1 or param2
  // we can do for assignment value of struct, concatenation, or calculation and others

  
  // return any DATA TYPE from the result of Stuff over here
}
1 Answers

As already mentioned, go is strongly typed language. However, there is this ting called generics, which allows certain flexibility in methods while still keeping it strict ("" == false would never be true).

Additionally there is interface{} type, it might suite the thing you are trying to achieve. Be aware it is not comparable type.

Related