60 lines
No EOL
1 KiB
Markdown
60 lines
No EOL
1 KiB
Markdown
# Z library
|
|
|
|
# dns example
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"github.com/zeevdiukman/z/dns"
|
|
"github.com/zeevdiukman/z/helper"
|
|
)
|
|
|
|
func main() {
|
|
dnsApp := dns.New()
|
|
dnsApp.Mux.HandleFunc(".", dnsApp.HandleTypeA)
|
|
go dnsApp.Run()
|
|
helper.StartHTTP()
|
|
}
|
|
```
|
|
|
|
# crypt example
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/zeevdiukman/z/crypt"
|
|
"github.com/zeevdiukman/z/helper"
|
|
)
|
|
|
|
func main() {
|
|
var _ = crypt.Encrypt
|
|
t := time.Now()
|
|
key := "1b1ef1cf714a412d57ec7be1647e6e1e7f8141a1cd009dd13b52041e5c62dbd6"
|
|
keyBytes, _ := hex.DecodeString(key)
|
|
plaintext := "hello, world!"
|
|
encryptedText, err := crypt.Encrypt(plaintext, keyBytes)
|
|
|
|
if err != nil {
|
|
fmt.Println("Error encrypting:", err)
|
|
return
|
|
}
|
|
decryptedText, err := crypt.Decrypt(encryptedText, keyBytes)
|
|
if err != nil {
|
|
fmt.Println("Error decrypting:", err)
|
|
return
|
|
}
|
|
tt := time.Since(t)
|
|
|
|
fmt.Println("Key:", key)
|
|
fmt.Println("Encrypted:", encryptedText)
|
|
fmt.Println("Decrypted:", decryptedText)
|
|
fmt.Println("Generated in", tt)
|
|
helper.PrintOldStyleMetrics()
|
|
}
|
|
``` |