Last active
May 30, 2022 16:13
-
-
Save rootVIII/24759b3711906548a07bb45ee430d727 to your computer and use it in GitHub Desktop.
Golang example variadic function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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