Class and Method design in Go

Newbie to Go Framework
Though I have been taking Go tutorials but when applied it practically, I am lost. Got few doubts in the code I have written.

The below is Python code

table1 = 
{
  ‘q1’: [3]
  ‘q2’:[8,2]
  “x”:[0xAAA]
}

class checkIDS(object): 

    t1 = 0xaa
    t2 = 0xae

   def classmethodA(a, val):
     try:

     except :

   def classmethodB(a, name):
      try:

      except :

  bv = {
	     “T1”:        0x01,
	     “T2”:        0x03,
       }


class modA(checkIDS)
     def __init__(self,zz):

     bv.update({“T1”:0x03})

The above Python code is translated to Go format as shown below

    type table1 struct 
        {
          q1  [3] byte
          q2 [8][2]byte
          x [0xAAA]byte
        }

    type object struct {
         a int
         b int
    }

How to redefine the below lines in Go ?

class checkIDS(object) and the methods below it?

I tried my best in defining as

func (self *A)

and unable to proceed further. How to define class as structs type in Go ?

Your python code is lacking appropriate whitespace, can you please edit your post and make it a codeblock?

Beyond that, there are no classes in go.

Just structs that can optionally have methods.

type s struct{}

func (s s) f() {
  fmt.Println("I'm here")
}

And even more importantly, there is no idea of inheritance in go.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.