Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 381
Good morning! Here's your coding interview problem for today.

This problem was asked by Paypal.

Read this Wikipedia article on [Base64 encoding](https://en.wikipedia.org/wiki/Base64).

Implement a function that converts a hex string to base64.

For example, the string:

`deadbeef`
should produce:
`3q2+7w==`

Pull request description:
Day381
Resolves #768.

Patch:
diff --git a/README.md b/README.md
index aa76e21..cb85432 100644
--- a/README.md
+++ b/README.md
@@ -376,4 +376,5 @@ problems from
 * [Day 378](https://github.com/vaskoz/dailycodingproblem-go/issues/762)
 * [Day 379](https://github.com/vaskoz/dailycodingproblem-go/issues/764)
 * [Day 380](https://github.com/vaskoz/dailycodingproblem-go/issues/766)
+* [Day 381](https://github.com/vaskoz/dailycodingproblem-go/issues/768)
 
diff --git a/day381/problem.go b/day381/problem.go
new file mode 100644
index 0000000..5bb7211
--- /dev/null
+++ b/day381/problem.go
@@ -0,0 +1,16 @@
+package day381
+
+import (
+	"encoding/base64"
+	"encoding/hex"
+)
+
+// Base64Delegate just delegates
+func Base64Delegate(hexs string) string {
+	data, err := hex.DecodeString(hexs)
+	if err != nil {
+		panic("bad hex input")
+	}
+
+	return base64.StdEncoding.EncodeToString(data)
+}


Test patch:
diff --git a/day381/problem_test.go b/day381/problem_test.go
new file mode 100644
index 0000000..bcba0de
--- /dev/null
+++ b/day381/problem_test.go
@@ -0,0 +1,40 @@
+package day381
+
+import "testing"
+
+// nolint
+var testcases = []struct {
+	hexs     string
+	expected string
+}{
+	{"deadbeef", "3q2+7w=="},
+}
+
+func TestBase64Delegate(t *testing.T) {
+	t.Parallel()
+
+	for _, tc := range testcases {
+		if result := Base64Delegate(tc.hexs); result != tc.expected {
+			t.Errorf("Expected %v, got %v", tc.expected, tc.hexs)
+		}
+	}
+}
+
+func TestBase64DelegateBadInput(t *testing.T) {
+	t.Parallel()
+
+	defer func() {
+		if err := recover(); err == nil {
+			t.Errorf("should have paniced with bad input")
+		}
+	}()
+	Base64Delegate("thisisnothex")
+}
+
+func BenchmarkBase64Delegate(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			Base64Delegate(tc.hexs)
+		}
+	}
+}