My name is Xie Wei, and I am a back-end programmer.
Their intelligence is general, technology iteration is very fast, in order not to always be in the entry level, to their own positioning is the back-end, further positioning at this stage is web background development.
In order to keep curious, I often try new technologies. In fact, it is not only technology, such as photography, presentation design, shooting videos, we media writing, etc., I often dabble-in them.
If I was a successful person at the moment, to see the above field, some people will envy said: “slash”, unfortunately, the next did not succeed, so, the above field will be certain procedures will be considered: “not business”, not important, important is: I am still a back-end programmer.
memory
We all know that memory has a forgetting curve, so the most important way to prevent forgetting is to use it often and repeatedly. That’s why, some people say: It’s easier to learn on the job, because the flow of work, projects, etc., don’t change frequently, you will be constantly focused on one or more projects to develop, over time, you will get more familiar with it, of course, you will do it faster. At this time, also called to reach the so-called: comfort zone. To make progress, you have to jump into the learning zone. Do it again.
The problem is that you have few opportunities to practice your skills outside of work.
Create opportunities
- Offer to take on more complex tasks
This is a much clearer, more complex task that you might try to use the new stack, and that gives you the opportunity to practice other skills, and that gets you into the learning zone.
If that’s the end of the company project, nothing too complicated, or the new project is similar to what you’ve seen, just in a different application scenario. At this point, if the task requires your participation, at this point, you’d better try a new structure, try a new technology point, although it is generally the same, you can improve the areas that you think the original system is not reasonable, so that can also create opportunities to enter the learning area.
But in my opinion, the average project development time is very tight, and the developer may not have enough time to think about it, and still use the original skill points, and then the opportunity to get into the learning area is wasted, you just use one experience and do two types of projects.
Old knowledge is replenished
In terms of experience and qualifications, you are not as good as others. You have limited access to resources. There are no new projects for you to develop independently, but only old projects for you to fix.
In the pit? Is it another pit?
- Complementary knowledge system
Even if it’s something you can do, have you ever tried to write it yourself, have you ever tried to make up for what you don’t know, have you ever tried to figure out if your development process is optimal,
Have you tried to summarize the technical points of the project, have you tried to distill the technical points that can be reused…
If you don’t have either, congratulations, you’ve found another entry point into the learning area: complementing the existing technology stack.
You may be able to use a programming language, but it depends on Google, stackOverflow, do you want to try to comb through the entire programming language knowledge, of course, the entry point is still related to work, because this
The most urgent, the most repetitive, the most frequently used.
Maybe you can use the database related knowledge, the optimization data knowledge point is not very understand, you want to try to find relevant information to make up for next.
Maybe…
Maybe you can also read the source code frequently, such as the implementation of the built-in library, before I would not pay attention to these, writing code is not very bottom, then often check the source code, with the IDE jump function
Can realize the source code reading, combined with the STRUCTURE of IDE, you can organize the functions, structures, methods and so on. So you can see it from the whole, you can see it a lot,
You can even draw some commonalities:
- For example, error handling of packages is generally defined in the top few lines of the package, and the format is consistent
- Such as
Interface
Is a collection of methods, built-in common onesInterface
Not really, many of the built-in packages implement each other - The package structure, for example, can instantiate a default, so that functions can be called directly, for example
http.DefaultClient
.
Read the source code of the library, what do I generally do? (Don’t focus too much on the implementation unless you understand it completely.)
- Official documents: Understand common usage methods
- Mind mapping: Output exportable structures, functions, methods, etc., still select the most commonly used
- The IDE
structure
Function, view the specific organization of the file, see the structure can be exported, functions, methods, etc - Continue to summarize
For example: The NET/HTTP package is the foundation for almost every Web framework, web request library in the Go world.
Pick up a book on HTTP. It’s a huge chunk of information.
With general historical experience, you might make a mind map like this.
The whole process is like this: the table of contents that you extract from a book, provided you have read the contents of the book.
2. Net/HTTP client
Network requests are divided into two levels: 1. The client initiates a network request 2. The server provides network requests to access resources
func getHandle(rawString string) {
response, err := http.Get(rawString)
iferr ! =nil {
return
}
defer response.Body.Close()
content, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(content))
}
Copy the code
It seems simple enough to initiate a web request using http.get.
To complete the picture, go to the source code and use the JUMP feature directly from the IDE.
In combination with IDE’s structure function, the original HTTP. Get is the source code with a default DefaultClient calling its method Get.
func Get(url string) (resp *Response, err error) {
return DefaultClient.Get(url)
}
Copy the code
The same goes for http.Post and http.PostForm.
Of course, you can customize a custom client and call its Do or Get, Post, PostForm methods, etc
type Client struct{... }Copy the code
At this point, your mental output might look something like this:
Ok, with regard to the NET/HTTP client layer, you should now know how to use it. You can either use the default, the default if it doesn’t meet your requirements, you
You can instantiate a client yourself, you can instantiate http.Request, and then call the client.Do method.
3. Net/HTTP server
The server side is more important, daily Web development, but also the vast majority of work in the server side.
How do I start a Web service?
type SelfHandler struct{}func (SelfHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
writer.Write([]byte("Hello Python"))}func main(a){
// method One
http.HandleFunc("/hello_golang".func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Hello Golang"))})// method Two
var self SelfHandler
http.Handle("/hello_python", self)
log.Fatal(http.ListenAndServe(": 9090", selfServerMux))
}
Copy the code
It consists of two steps: defining routes and actions after routes are triggered, and starting services.
Look at the source code, the server side is more complex than the client side.
func Handle(pattern string, handler Handler) { DefaultServeMux.Handle(pattern, handler) }
func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
DefaultServeMux.HandleFunc(pattern, handler)
}
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}
Copy the code
An internal default DefaultServeMux(request router) was used. Handler is an interface. SelfHandler in the previous section implements the Handler interface.
Before, you might have been a little confused about the relationship between Handle, HandleFunc, and Handler. You should see it better by comparison.
Now that you are using the default DefaultServeMux, you can customize ServeMux as well.
func main(a){
var selfServerMux *http.ServeMux
selfServerMux = &http.ServeMux{}
selfServerMux.HandleFunc("/hello_golang_2".func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Hello Golang 2"))
})
log.Fatal(http.ListenAndServe(": 9090", selfServerMux))
}
Copy the code
You can also customize the configuration information of the server.
func main(a){
var selfServer http.Server
var selfMux *http.ServeMux
selfMux = &http.ServeMux{}
selfMux.HandleFunc("/d".func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Hello Mux"))
})
selfServer = http.Server{
Handler: selfMux,
Addr: "localhost:9098",
}
log.Fatal(selfServer.ListenAndServe())
}
Copy the code
At this point, your mind map looks something like this:
Of course, enterprise-level Web services development also needs to consider:
- Routing design
- Request parameter verification
- Response information
- Front end separation
- Error handling message
- .
4. Use some Web frameworks
- gin
- echo
- iris
- beego …
conclusion
The above is my daily thinking, I hope to inspire you.
The whole process, in fact, is the process of combing your knowledge, if you contact a lot of knowledge, do not often reason, in your mind, may just pile up, when used can not timely call out, so often say: I have seen this ah.
Timely combing, modular in the mind, the call is much more natural and smooth, of course, forced by the forgetting curve, these actions, you also need to repeat.