If you are Xiaobai, this set of information can help you become a big bull. If you have rich development experience, this set of information can help you break through the bottleneck
2022web full set of video tutorial front-end architecture H5 vue node applet Video + data + code + interview questions.
On January 12, it was originally the time for the release of the project. Looking at the pages that were a little ugly, I kept adjusting the style. I didn't expect that several bug s started on me when it was released that night... It was not released until 1:00 after checking and repairing with colleagues.
The following is the description and solution of each pit. The screenshot is the demonstration of this machine, which is only for reference ~.
Question 1: start prompt: redis connection failed
For the first packaging, take the compiled binary directly to the distribution version. Inexperienced, I thought it would be a fat binary. As a result, no matter how you check the effect of configuration packaging, you can't start it correctly using the redis parameter in the configuration:
Therefore, several configurations yml are attached and placed in the binary peer directory. restart app
redis problem solved.
Question 2 missing template
A new error message appears, as shown in the figure below
It is judged that the relevant template resources under the template cannot be accessed. By comparing the size of the source folder and the actual packaged products, it is found that the packaging is small. It is estimated that only go code can be packaged, while all configuration and static resources need to be copied.
So upload the assert resource. Press the corresponding folder and start successfully:
Problem 3: the cookie cannot be obtained normally, so that the home page cannot be accessed after login
Foreshadowing: the home page is to obtain a "session_id" header of the front-end request, get the session data, and further obtain a token string stored in the session when the login is successful for authentication. Valid session returned by the front-end incoming gin_ ID to access the page requiring permission. If the sessionid data in the cookie is not available or invalid, the login page will be returned and the newly created sessionid value will be written to the front end.
The session id will be written to the front-end cookie
//Writeback cookie c.SetCookie(SessionCookieName, sd.GetID(), 3600, "/", "localhost", false, true)
In combination with the process of login success - > write sessionid to Cookie - > get sessionid in cookie - > use or create sessionid - > get cookie on the home page and analyze session data, if the cookie is written normally, it should be able to jump to the home page.
During verification, it is found that after successful login, it jumps back to the login page, which has been in a dead cycle, while the non authentication page is accessed normally. After investigation, the cookie: session cannot be found_ Field of ID
This problem has not been found during native development. It reappears when deploying and distributing the version! Use my colleague's computer to access the program deployed on my machine, which is reproduced! Maybe it's the * * cookie domain** With this problem, continue to go online for help
1. Blog: gin set to get cookie s [setting failed] - Go language Chinese website - Golang Chinese community
Online suggestion: do not write directly to the domain: 127.0.0.1 and 0.0.0.0
2. Do you need to write cookie s in combination with the actual deployment ip?
With this in mind, I wrote a tool on the Internet to obtain the local ip and requester ip, and directly write it into all possible ip:
func GetLocalIP() []string { var ipStr []string netInterfaces, err := net.Interfaces() if err != nil { fmt.Println("net.Interfaces error:", err.Error()) return ipStr } for i := 0; i < len(netInterfaces); i++ { if (netInterfaces[i].Flags & net.FlagUp) != 0 { addrs, _ := netInterfaces[i].Addrs() for _, address := range addrs { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { //Get IPv6 /*if ipnet.IP.To16() != nil { fmt.Println(ipnet.IP.String()) ipStr = append(ipStr, ipnet.IP.String()) }*/ //Get IPv4 if ipnet.IP.To4() != nil { fmt.Println(ipnet.IP.String()) ipStr = append(ipStr, ipnet.IP.String()) } } } } } return ipStr } // GetRequestIP get ip func GetRequestIP(c *gin.Context) string { reqIP := c.ClientIP() if reqIP == "::1" { reqIP = "127.0.0.1" } return reqIP }
The cookie is normally written back to the browser! You can jump to the home page! It's already 1:00 a.m~
It's not easy to code. Please give me some praise_