Skip to content

Instantly share code, notes, and snippets.

@rootVIII
Last active May 30, 2022 16:13
Show Gist options
  • Save rootVIII/24759b3711906548a07bb45ee430d727 to your computer and use it in GitHub Desktop.
Save rootVIII/24759b3711906548a07bb45ee430d727 to your computer and use it in GitHub Desktop.
Golang example variadic function
package main
import (
"fmt"
"strconv"
)
type example struct {
container []byte
}
func (e *example) toByte(incoming ...string) {
for _, item := range incoming {
val, _ := strconv.Atoi(item)
if val < 256 {
e.container = append(e.container, uint8(val))
}
}
}
func main() {
ex := &example{}
ex.toByte([]string{"18", "89", "255", "320", "43"}...)
for _, byteVal := range ex.container {
fmt.Printf("%X\n", byteVal)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment