Code review requested on function declaration

Its a taking time to adapt from Python to Golang and I am seeking help in reviewing my go code
Trying to convert a Python code to Golang. I have re-written code in Golang. Attached is the code screenshot. Kindly review my code and let me know the errors. Thanks

Python code structure

Python code structure

class CallmainFunc(obj):

   def __init__(self, **kwargs):							     
        self.variable = None      								                                                 
    
   def funcT1(self, f1, f2):        							                                                      
        return f2																		      
		 							  
   def funcT2(self, p1):								     							
        return None         									   
						                                                    
   def funcT3(self, t1=None):             						                                                        
        return False										
											    
   def funcT4(self, z1, z2):	                                                           
          z1             - The z1 instance for a car brand
          z2             - list of available cars models
        '''
        pass


class AA(obj):
  def ..

Equivalent Go Code

> //KWAG = simulation of python kwargs
>   
> type KWAG map[string]interface{}
> 
> type CallmainFunc struct {}  //tryin to simulate Class as type 
>    struct CallmainFunc(obj) {
>     	func init(self, args KWAG) {
>            self.variable = nil                                                       
>     	}
>       
>      func funcT1(self, f1 string, f2 string) string {                                                    
>        	    return f2								      
> 	}	
> 									  
>      func funcT2(self, p1 string) {								
>             return nil    
> 	}                                                              
>        
>      func funcT3(self, t1 string) bool {                                                    
>      	    return false
> 	}
>  	                                                          
>  //dont know how to re-write funcT4

Post code as text. Do not post code as images.

1. Important Note

  1. DO NOT translate any codes directly. Try to understand the algorithm/meaning before writing out using the targeted language in its own way. This applies to any languages both programming and linguistic in nature (not just Go alone).
  2. DO NOT be a translator if your have not master even the basic of the targeted language. You will create a lot of burden for your team (potentially rewrite everything you did from scratch). Stick to Go package development and complete your Go tutorial to get some experience first. You have been warned!

2. Use structure interface over internal function

It’s something as such:

type CallmainFunc struct {}

func (x *CallmainFunc) FuncT1(f1, f2 string) string {
    return f2
}

...

func (x *CallmainFunc) FuncT3(t1 string) bool {
    return false
}

Some notable changes would be:

  1. Instead of passing self as a parameter, you can call it directly using x (See: A Tour of Go, and Effective Go - The Go Programming Language)
  2. Also, avoid using self as general practice (not a rule). Interface in Go is not OO so do not assign OO common terminologies for it.

3. Insufficient information for funcT2 output

The undocumented funcT2 did not specify the output type. On Go side, you cannot simply return nil if your function is not expecting to return any output.

func FuncT2(self, p1 string) {   // did not expect any output

You need to query info from your python developer for FuncT2 output data type. If you really need to return nil, then the function should look something like:

func (x *CallmainFunc) FuncT2(p1 string) error { // assuming this is what is expected from Python side
    return nil
}

Otherwise, a simply execution without return value is fine:

func (x *CallmainFunc) FuncT2(p1 string) {
    return
}

4. Insufficient information whether all the methods are exportable

You need to determine are those methods (funcT1, funcT2, …) meant to be exportable (accessible outside package) or otherwise. Go has a strict rule for it (notice I re-capitalized all your function taking the assumption that they are all exportable, which is an expectation from Python side). See (A Tour of Go). In short:

// This is exported function (starts with capital case letter) which is visible
func (x *CallmainFunc) FuncT3(t1 string) bool { 
    ...
}

// This is internal function (starts with lowercase letter) which is private to that package itself
func (x *CallmainFunc) funcT3(t1 string) bool { 
    ...
}

5. Insufficient Info for Init function

On Go side, are the keywords already processed before creating the structure? If yes, then create an exported New package function to create the structure object instead:

func New(kwargs... string) *CallmainFunc {
    // process your kwargs (an array)
 
    return &CallmainFunc {
        // assign your values here. Example:
        // Name: "John Smith",
    }
}

However, since your init function on Python side does nothing and the assigned variable is not used anywhere, you can discard that function implementation entirely in Go, even with the New(...) function above. Reason:

  1. Go compiler will not compile for unused variables.
  2. New(...) function is redundant if the struct does not need any pre-processing. Your user can create the structure directly like &CallmainFunc{ ...} instead.

6. funcT4 is incomprehensible without documentation

  1. funcT4 is not comprehensible without its documentations. Looks like work in progress spaghetti codes.
  2. Notice that after z2, the triple quote string is open but not closed which means anything after those quotes are string in nature (commented out). Hence, I strongly suspect the function is work in progress. You need to consult the original developer.

@jennifer

Totally understand your difficulty in moving to new language. There are many good Go tutorials for beginners and strongly encourage to understand the basic concept and run the sample codes in play.golang.org. This helped me too