??
? ????? ??? WebSocket ??????? ??? ??? ???????. Gin ? Go? ???? ??? ???? WebSocket ??? ????? ????, ???? ????, ??? ?? ?????? ????? ?????????.
???? ??
https://github.com/tom-takeru/web-socket-demo
? ??? ????? ???? ????? ????? ???????. ??? ????? ???? ?????:
./backend ├── go.mod ├── go.sum ├── main.go └── stores └── messages.go
?? ???? ? ??
- go.mod: ?? ???? ??? ?????.
- main.go: WebSocket ??? ????? ??? ???? ??????? ??????.
- stores/messages.go: ?????? ??? ???? ??? ???? ?????.
?? ?? ??: main.go
main.go? WebSocket ?? ??????? ?? ??????. Gin ???? ???? WebSocket ??? ???? WebSocket ?? ??? ?????.
?? ??
package main import ( "encoding/json" "net/http" "sync" "time" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" "github.com/tom-takeru/web-socket-demo/backend/stores" ) var ( upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { origin := r.Header.Get("Origin") // NOTE: This project is for local development only. return origin == "http://localhost:3000" }, } messageStore = stores.NewMessageStore() clients = make(map[*websocket.Conn]bool) clientsMu sync.Mutex ) func handleWebSocket(c *gin.Context) { conn, err := upgrader.Upgrade(c.Writer, c.Request, nil) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to upgrade to WebSocket"}) return } defer conn.Close() clientsMu.Lock() clients[conn] = true clientsMu.Unlock() // Send existing messages to the new connection for _, msg := range messageStore.MarshalMessages() { conn.WriteMessage(websocket.TextMessage, msg) } for { _, message, err := conn.ReadMessage() if err != nil { break } var msgData map[string]string if err := json.Unmarshal(message, &msgData); err != nil { break } timestamp := time.Now().Format(time.RFC3339) msgData["timestamp"] = timestamp messageStore.AddMessage(msgData) modifiedMessage, err := json.Marshal(msgData) if err != nil { break } clientsMu.Lock() for client := range clients { if err := client.WriteMessage(websocket.TextMessage, modifiedMessage); err != nil { client.Close() delete(clients, client) } } clientsMu.Unlock() } clientsMu.Lock() delete(clients, conn) clientsMu.Unlock() } func main() { r := gin.Default() r.GET("/ws", handleWebSocket) r.Run("localhost:8080") }
?? ??
- ?? ??: ??? ?????? ???? ???? ???? ?????? ??? ???? ?????.
- WebSocket ?? ??: ?? ??, ??? ?????? ? ?? ?? ??? ?????.
??
WebSocket ?? ??????? ??? ????? Gin ? Go? ???? ??? ??? ????? ???? ??? ?????. ???? ??? ?????? ??? ??? ???? ?? WebSocket? ?????? ? ??????? ??? ? ?????? ??? ?? ??? ?? ??? ???.
?? ???? ?? ??? WebSocket ?? ???? ?? ???????.
??? ??
- WebSocket? ??? ??? ? ?????? ?? - ??
- WebSocket? ??? ??? ? ?????? ?? - ?????
? ??? WebSocket? ??? ??? ? ?????? ?? - ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











GO? ????? ????? ??? ????? ??????. ?? ??? ?? ?????. 1. ? ??? ?? : Linux ????? ?? ??? ?????? ??? ??? ? ????. 2. ?? ??? ??? ?? ???? ???? ?? ??? ????? ?? ??? ?? ?? ??? ?? ??? ? ? ????. 3. ?? ?? ???? ?? : ?? ????? ??? ??? ?? ??? ??? ???? ??????. 4. ??? ?? ??? : ??? ???? ????? ?? ?????? ? ???? ? ? ??? ??? ? ??? ?????. ??? ??? CLI ??, ???? ??? ? ?? ????? ????? ????? ????? ?? ??? ??? ???? ????? ???? ??? ?????.

goensuresmemorysafety? ?? MemolemanucameThrougatomaticgargarbagecollection, nopointerarithmetic, safeconcurrency, andruntimechecks.first, go'sgarbagecollectoricallyally reclaimsunusedmemory, ??, itdisallowspointe, itdisallowspointe ??

GO?? ?? ??? ???? MAKE ??? ?? ?? ?? ? ??????. ?? ??? ???? ??? ??? ???? ?? ? ???? ?? ? ?? ??? ???? ?? ? ???? ??? ??? ? ????. ?? ??, ch : = make (Chanint, 10)? ?? 10 ?? ?? ?? ??? ??? ?? ??? ????. ???? ?? ??? ??, ??? ???? ?? ???? ??? ???? ???? ?? ? ??? ??? ????? ?????. ??? ??? ?, ?? : 1. ?? ??? ??? ??? ?? ??? ??? ??? ?? ?????????. 2. ??? ??? ??? ??? ??? ???? ?? ???????. 3. ??? chanstruct {} ??? ?? ?? ? ? ????. ???? ?????? ??? ?, ??? ??? ?? ? ???? ?????.

GO? ??? ?????? ??????. C? ?? ??? ? ??? ??? ?? ??? ?? ??? ? ??? ???? ?? ?????. 1. ?? ? ???? ?? ???? Go? OS ???? ?? ? ????? ????? ??? ??, ??, ?? ??? ? ???? ?? ?????. OS.ReadFile? ???? ? ?? ??? ?? ??? ?????. ?? ???? ?? ?? ?? ??? ???? ? ?????. 2. ???? ?? ???? OS/EXEC ???? exec.command ??? ?? ??? ????, ??? ????, ?? ??? ????, ?? ? ?? ??? ?????? ?? ??, ??? ?? ? ?? ????? ??? ???? ????? ?? ? ? ????. 3. ???? ? ??? ???? Net ???? TCP/UDP ?????, DNS ?? ? ?? ??? ?????.

GO ???? ?? ??? ????? ?? ???? ????? ?? ? ???? ???? ??? ??? ???? ????????. ?? ???? ??? ?, ???? ? ??? ?? ??? ???? ?? ?? ? ? ????. 1. func (rrectangle) area () int? ?? ? ???? ???? rect.area ()? ?? ?? ??????. 2. ??? ?? ???? ?? func (r*???) setwidth (...)? ?? ??? ???? ???? ???? ?? ??? ???? ?????. 3. ??? ?? ? ?, ?? ??? ??? ?? ? ???, ?? ??? ?? ?? ?? ? ???. 4. Go? Getter/Setter? ??? ???? ??????.

GO?? ?????? ??? ???? ?? ??? ???? ?????. ?????? ??? ???? ???? ??? ??? ???? ?? ??? ?????? ???? ??????. ?? ??, speak () ???? ?? ? ??? ?????? ???? ???? ???? ?? ??? ???? ?? ? ? ????. ?????? ???? ??, ?? ?? ?? ?? ? ????? ?? ????? ???? ? ?????. ?????? ???? ????? ???? ???? ??? ??? ???? ??? ?? ??? ???? ?? ?????? ?????. ???? ?? ???? ??, ??, ?? ?????? ?? ???? ??? ? ?? ???? ?????. ?? ??, ?? ?? ??? ?? ??? ??? ???? ??? Anno? ??? ? ????.

Go Language?? ??? ??? ?? ??? ??? ? ?? ??? ?? ?????. 1.Strings.contains ()? ???? ?? ???? ???? ??? ??? ???? ?? ?? ???? ? ?????. 2.strings.index ()? ???? ?? ???? ???? ??? ?? ? ??? ???? ??? -1? ?????. 3.strings.replaceall ()? ?? ???? ?? ??? ?? ? ? ??? Strings.replace ()? ?? ?? ?? ?? ? ? ????. 4.Len () ??? ???? ??? ??? ?? ? ????? ?? ??? ?? ? ?? ??? ???? ?????? ???????. ??? ??? ?? ??? ???, ??? ?? ?? ? ??? ??? ?? ?????? ?????.

TheGoiopackageprovidesinterfaceslikeReaderandWritertohandleI/Ooperationsuniformlyacrosssources.1.io.Reader'sReadmethodenablesreadingfromvarioussourcessuchasfilesorHTTPresponses.2.io.Writer'sWritemethodfacilitateswritingtodestinationslikestandardoutpu
