Skip to content

Instantly share code, notes, and snippets.

@ppetko
Last active April 5, 2019 17:46
Show Gist options
  • Save ppetko/1118b5bd1d4ab3d6de79b90aeebb822c to your computer and use it in GitHub Desktop.
Save ppetko/1118b5bd1d4ab3d6de79b90aeebb822c to your computer and use it in GitHub Desktop.
Random String
/*
For this implementation I'm using third party service for getting random data.
*/
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
var RANDOM_DATA string = "https://www.random.org/cgi-bin/randbyte"
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", RANDOM_DATA, nil)
req.Header.Add("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
resp_body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(resp_body))
}
/*
Output
╚═>go build random.go
╔ǁpetko.petkov@dev-vm:~ 9 files, 6.3M
╚═>./random
V*���P]�)|K���*�q������L\>�T�G�?f"T��flkV֔�9�m��E<������H��AG��_`_���x=0����8���E��W᷽.�N)�c��فh!���O�BJ�Ϣ�g�(=КA�J2~v Wݳ��K�6ɥ�� mzB����A$=�_A�F\��S�[��^_6‚������3ⷱ0��Jrn�'�(�[�ٹ�@�ޞׁ
�����"��|�S�����v��Z���Ez�==Z��uH4$���t��n
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment