How can the concept of member variables be the most elegant in non-object-oriented languages?

is actually learning to write a background service in GO recently.

want to rewrite a previous service,

an object is new when a previous request comes in. Then manipulate the object.

within the class, member variables can be defined and shared by all member functions. There are some functions that share these variables.

but when refactoring with GO, because GO has no concept of classes, it feels like something is missing.

define a global variable that will be shared by all requests (not a request to generate a new variable).

do not define global variables, many functions use the same thing, all functions need to constantly return parameters for the next function to use.

it"s always awkward to use structs to simulate classes. How can you modify it to make your code concise and efficient?

I do not know whether the description of the problem is clear or not, and I would like to ask all the bosses for advice.

Nov.19,2021

A

structure is a class. What's wrong with
defining a structure that contains variables that need to be shared, then var a global pointer to the structure, and then new it out when initializing the service?

var srv *Service

type Service struct{
    public map[string]interface{}
}

func InitService(){
    srv = &Service{
        public: make(map[string]interface{}),
    }
}

func main(){
    InitService()
    // TODO
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c45d-2c2e6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c45d-2c2e6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?