Skip to content

Instantly share code, notes, and snippets.

junftnt

Block or report user

Report or block junftnt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@junftnt
junftnt / multivalChSample.go
Created Aug 2, 2019 — forked from slav/multivalChSample.go
Golang sending sending multiple values through channel
View multivalChSample.go
package main
import "fmt"
func f(c chan func() (int, string)) {
c <- (func() (int, string) { return 0, "s" })
}
func main() {
c := make(chan func() (int, string))
@junftnt
junftnt / aes-256-gcm.go
Created Aug 1, 2019 — forked from cannium/aes-256-gcm.go
golang aes-256-gcm
View aes-256-gcm.go
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
)
@junftnt
junftnt / aes256-gcm.go
Created Aug 1, 2019 — forked from kkirsche/aes256-gcm.go
AES-256 GCM Encryption Example in Golang
View aes256-gcm.go
package example_test
import (
"crypto/aes"
"crypto/cipher"
"hex"
"io"
)
// AES-GCM should be used because the operation is an authenticated encryption
@junftnt
junftnt / rsasign.go
Created Jul 31, 2019 — forked from hansstimer/rsasign.go
Go: rsa signpkcs1v15 signing
View rsasign.go
package main
import (
"bytes"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"fmt"
)
@junftnt
junftnt / rpc-tls-client.go
Created Jul 30, 2019 — forked from artyom/rpc-tls-client.go
Go RPC over TLS.You have to create the following keys: certs/client.crt, certs/client.key, certs/server.crt, certs/server.key. client.crt and server.crt should be signed with ca.crt, which should be concatenated to both client.crt and server.crt. It's easier to do with easy-rsa: http://openvpn.net/index.php/open-source/documentation/howto.html#pki
View rpc-tls-client.go
package main
import (
"crypto/tls"
"crypto/x509"
"log"
"net/rpc"
)
func main() {
@junftnt
junftnt / rsa_util.go
Created Jul 8, 2019 — forked from miguelmota/rsa_util.go
Golang RSA encrypt and decrypt example
View rsa_util.go
package ciphers
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"crypto/x509"
"encoding/pem"
"log"
)
@junftnt
junftnt / custom_json.go
Created Dec 7, 2018 — forked from mdwhatcott/custom_json.go
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
View custom_json.go
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {
@junftnt
junftnt / go
Created Dec 6, 2018 — forked from yaxinr/go
invoke(call) struct method in golang
View go
package myreflect
import (
"fmt"
"reflect"
)
// Invoke - firstResult, err := invoke(AnyStructInterface, MethodName, Params...)
func Invoke(any interface{}, name string, args ...interface{}) (reflect.Value, error) {
method := reflect.ValueOf(any).MethodByName(name)
View reflection1_4.go
type Foo struct {
A int `tag1:"First Tag" tag2:"Second Tag"`
B string
}
func main() {
sl := []int{1, 2, 3}
greeting := "hello"
greetingPtr := &greeting
f := Foo{A: 10, B: "Salutations"}
@junftnt
junftnt / translate.go
Created Dec 5, 2018 — forked from hvoecking/translate.go
Golang reflection: traversing arbitrary structures
View translate.go
// Traverses an arbitrary struct and translates all stings it encounters
//
// I haven't seen an example for reflection traversing an arbitrary struct, so
// I want to share this with you. If you encounter any bugs or want to see
// another example please comment.
//
// The MIT License (MIT)
//
// Copyright (c) 2014 Heye Vöcking
//
You can’t perform that action at this time.