# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048
# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
openssl ecparam -genkey -name secp384r1 -out server.key
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
// MarshalJSON will marshal v to JSON. Pretty prints if pretty is true. | |
func MarshalJSON(v interface{}, pretty bool) []byte { | |
var b []byte | |
var err error | |
if pretty { | |
b, err = json.MarshalIndent(v, "", " ") | |
} else { | |
b, err = json.Marshal(v) | |
} |
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
if f, err := os.Stat(s.dataDir); err != nil && os.IsNotExist(err) { | |
if err := os.Mkdir(s.dataDir, 0755); err != nil { | |
return errors.Wrapf(err, "data_dir %s does not exist, failed to create it", s.dataDir) | |
} | |
} else if !f.IsDir() { | |
return fmt.Errorf("path data_dir %s exists and is not a directory", s.dataDir) | |
} |
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 ( | |
"bufio" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"strings" | |
) |
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
//code copy kapacitor | |
signalCh := make(chan os.Signal, 1) | |
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM) | |
m.Logger.Println("I! Listening for signals") | |
// Block until one of the signals above is received | |
select { | |
case <-signalCh: | |
m.Logger.Println("I! Signal received, initializing clean shutdown...") |
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" | |
"net" | |
"sort" | |
"strings" | |
) | |
func main() { |
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 CopyFile(src, dst string) (int64, error) { | |
if src == dst { | |
return 0, nil | |
} | |
sf, err := os.Open(src) | |
if err != nil { | |
return 0, err | |
} | |
defer sf.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
func IsURL(str string) bool { | |
return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://") | |
} | |
func IsGIT(str string) bool { | |
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "[email protected]:") || (strings.HasSuffix(str, ".git") && IsURL(str)) | |
} |
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 ( | |
"crypto/tls" | |
"crypto/x509" | |
"fmt" | |
"io" | |
"log" | |
) |
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" | |
"net" | |
) | |
func main() { | |
// obtained from ping -c 1 stackoverflow.com, should print "stackoverflow.com" | |
addr, err := net.LookupAddr("198.252.206.16") |