Skip to content

Instantly share code, notes, and snippets.

@kamal-github
Created January 22, 2021 12:38
Show Gist options
  • Save kamal-github/25b31c363e667ef0bcc62062b3927b19 to your computer and use it in GitHub Desktop.
Save kamal-github/25b31c363e667ef0bcc62062b3927b19 to your computer and use it in GitHub Desktop.
Remove first element from slice
// https://play.golang.org/p/7oTksbq9ioW
package main
import (
"fmt"
)
func main() {
removeOne([]Conn{Conn{i: 100}, Conn{i: 200}, Conn{i: 300}, Conn{i: 400}, Conn{i: 500}})
}
type Conn struct {
i int
}
func removeOne(freeConn []Conn) {
for i := 0; i < len(freeConn); i++ {
last := len(freeConn) - 1
freeConn[i] = freeConn[last]
freeConn[last] = Conn{}
freeConn = freeConn[:last]
fmt.Println("freeConn after i ", freeConn, i)
i--
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment