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
// Client | |
creds, err := credentials.NewClientTLSFromFile("service.pem", "") | |
if err != nil { | |
log.Fatalf("could not process the credentials: %v", err) | |
} | |
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds)) | |
if err != nil { | |
log.Fatalf("did not connect: %v", err) | |
} | |
defer conn.Close() |
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
// Client | |
b, _ := ioutil.ReadFile("ca.cert") | |
cp := x509.NewCertPool() | |
if !cp.AppendCertsFromPEM(b) { | |
return nil, errors.New("credentials: failed to append certificates") | |
} | |
config := &tls.Config{ | |
InsecureSkipVerify: false, | |
RootCAs: cp, | |
} |
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
// Client | |
config := &tls.Config{ | |
InsecureSkipVerify: false, | |
} | |
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(credentials.NewTLS(config))) | |
if err != nil { | |
log.Fatalf("did not connect: %v", err) | |
} | |
defer conn.Close() |
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
// Client | |
config := &tls.Config{ | |
InsecureSkipVerify: true, | |
} | |
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(credentials.NewTLS(config))) | |
if err != nil { | |
log.Fatalf("did not connect: %v", err) | |
} | |
defer conn.Close() |
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
// Client | |
conn, err := grpc.Dial(address, grpc.WithInsecure()) | |
if err != nil { | |
log.Fatalf("did not connect: %v", err) | |
} | |
defer conn.Close() | |
// Server | |
s := grpc.NewServer() | |
// ... register gRPC services ... |
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
#!/bin/bash | |
sudo apt-get update | |
sudo apt-get -y upgrade | |
sudo apt-get -y install make | |
curl -O https://storage.googleapis.com/golang/go1.12.6.linux-amd64.tar.gz | |
tar -xvf go1.12.6.linux-amd64.tar.gz | |
sudo mv go /usr/local | |
echo 'export PATH=$PATH:/usr/local/go/bin |
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
func main() { | |
ipn := &net.IPNet{ | |
IP: net.IPv4(10,200,0,0), | |
Mask: net.CIDRMask(24, 32), | |
} | |
gw := calcGatewayIP(ipn) | |
fmt.Printf("%v", gw ) | |
} |
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
func maxDepth(root *TreeNode) int { | |
if root == nil { | |
return 0 | |
} | |
d := 1 + max(maxDepth(root.Right), maxDepth(root.Left)) | |
return d | |
} | |
func max(a, b int) int { | |
if a > b { |
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
func threeSum(nums []int) [][]int { | |
result := [][]int{} | |
check := make(map[int]bool) | |
for i := 0; i < len(nums)-2; i++ { | |
if check[nums[i]] { | |
continue | |
} | |
for _, v := range twoSum(nums[i+1:], -nums[i]) { | |
if !(check[v[0]] || check[v[1]]) { | |
result = append(result, append(v, nums[i])) |
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 ( | |
"container/heap" | |
"fmt" | |
) | |
type mHeap struct { | |
value int | |
array int |