I can accomplish all kinds of business requirements without this thing. What"s the use of this?
I can accomplish all kinds of business requirements without this thing. What"s the use of this?
this is not the problem of golang, this is why programming for interfaces
it is recommended to take a look at the design pattern
golang interface {} one can represent the interface in the design pattern, and the other can be seen as a void* similar to C #.
strongly typed languages are added to maintain the advantages of dynamic languages. Similar to Object
in java, it is very useful. The object-oriented design of golang is based on interface {}. If you don't use it, you should be a programming
master to use this to implement type OOP development. Interface-oriented programming.
does not mean that if you can complete all kinds of business, the features of the language you do not use are useless. Instead, you should reflect on why you do not use this important feature.
take the most simple and commonly used sorting, for example, without interface {}, you have to write similar code n times for different types of parameters, similar to the idea of the CPP template.
needs to be clear about the difference between interface and interface {}. One is the syntax mechanism of go for data abstraction and decoupling, and the other is the concrete implementation of this mechanism. The former should be encouraged, while the latter should be used with caution.
large projects or infrastructure projects are often built without interface to implement data abstractions and interfaces. Of course, it also depends on the specific requirements, go is not a strong paradigm, go/channel/interface/reflect these features do not say certain use, as long as you think the code architecture can perfectly match the requirements. Of course, it doesn't mean that what you don't use is useless. I suggest you take a look at different types of open source projects and experience it.
with regard to interface {}, you should be careful at all times. There is a risk of abuse and poor maintainability. But in line with go's pragmatic philosophy, it can be used if it can perfectly match the needs.
Previous: The .then in Promise.all is executed without waiting for the promise execution in it to complete
Next: How to use the react ant design mobile form and how to get the data to report an error
have you ever used goquery? I want to use an agent to crawl. Does goquery support it? After looking for it, I don t seem to find ....
Overview: the younger brother s program can query the sql in the database and write it into excel performance by entering the database type, database connection string, executing sql or files containing sql. Currently, 25W pieces of data are exported,...
introduce Mutex into the object to ensure atomicity, but when the object is a value reference, it is found that the cable has no effect. What is its internal implementation logic? the code is as follows: package main import ( "fmt" ...
popularize the QR code what to do when 1 out of 1 million people cannot generate a QR code? ...
I want to package an ios sdk, instruction with gomobile bind instruction. There is always a unknown GOARCH: " " error in the execution of the sdk, instruction. The error is as follows: AndroidmacGOARCH, ...
has anyone ever used a reliable golang TCP services framework? the framework had better have the following two modules: 1. Session management of connections 2. The framework can customize the protocol ...
firewall, the integrated environment of system Centos7, lnmp.org, does not have the permission to run mysql. Iptables has been restarted. Refresh authorization error: Mysql user:Iptables: New processing: 1. Modify mysql configuration file vi ...
goal: golang service, prepare to get banner information of ip:port. if ip:port is http, you can get http response, if it is ssh service, you can get ssh service output information. Such as version information. pre-condition: the corresponding tcpAddr...
< hr > finally found that time.Sleep (100 * time.Millisecond) will affect the database. After removing it, I didn t encounter the problem of busy buffer . < hr > I have encountered some problems in converting a piece of data from Table 1 to Table ...
other people s project code is as follows jsonStr := `{"Name":"lepig", "Age":100}` abc := []byte(jsonStr) var result []string if err := json.Unmarshal(abc, &result); err != nil { fmt.Println(err) ...
how do I convert it? func GetPlan(c *gin.Context){ expect := c.PostForm("expect") prevexpect,_ := strconv.Atoi(PrevExpect()) sql := "SELECT * from plan pl " + "left JOIN program pr on pl.program_id = p...
etc rc.d rc.local and etc rc.local are both given execution permissions etc rc.d rc.local and etc rc.local are configured as follows -sharp! bin bash -sharp THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES -sharp -sharp It is highly advisable to ...
ask for advice background uses beego to build scenario description: background has some operations for each row of data, such as editing and deletion, etc. Now the server has passed the InsertFilter time before routing permission detection. now it j...
recently encountered a problem, go write websocket server how to achieve file upload function? Baidu Google did not find the answer they wanted. Is there any example of a third party or that can run successfully? tried to search for some answers, but ...
1. Is learning the go language and trying to write a website, one of the functions is that after the user logs in, all the file directories contained by the user are displayed on the home page of the user, that is, the file information is mapped. At pres...
whether this situation can only be judged by sync.Map and Channel ....
which language has more advantages in building short video websites? The mobile phone will be used later. Is there any similar source code reference for ? ...
similar to GORM, execute some functions before and after executing the query by registering them db.Callback().Create().Before("gorm:create").Register("update_created_at", updateCreated) db.Callback().Create().After("gorm:creat...
I am thinking about a question: how to downgrade the service? for example, there was an interface before, and an average was determined through the other three interfaces. Hypothetically, it doesn t necessarily make sense. To get the location of the ...
currently I want to use golang for microservices, but different web frameworks are used between different services such as gin,beego,echo, Service registration discovery uses consul how to choose a gateway? No choice of go gateway has been fo...