在go中装饰基本数据类型

I am starting new application in go.

I know that we can't monkey patch go code. So if we want to do some hacks with basic data types like int, float, string, etc.. its not possible.

So, i am thinking to create new type for these basic things and use them througout the application instead of the basic ones. Later if we want to overwrite some of these methods or we want to add some new methods, we can overwrite these new types.

Is this good way of doing??

Following is the sample code:

type NewInt Int

or

type NewInt struct{
    Int
}

Here if i am creating a variable like var test NewInt = 16, will it create 2 objects internally(one for basic int and other for newint) by creating memory issue?? or will it use same object for both??

How can i debug this scenario?? How can i collect all the existing objects in heap after creating a variable??

I think the fundamental route that you are going down will cause you problems.

You shouldn't really be wrapping / mocking the primitive data types, such as int, string etc. But instead creating higher level abstractions; in the form of interfaces.

You mention needing to "overwite some methods" on your new types; but this should be done at the interface level and not the data type level.

You will also find it much harder to consume any other go packages, as you will constantly be converting from NewInt to int to pass into other packages.

If you provide an example of when you plan on using the NewInt type datatypes, then I can provide an example of how to do it with interfaces instead.