From 3173b06a417a52edf5649e2234eaf09359a768f1 Mon Sep 17 00:00:00 2001 From: "marko.tikvic" Date: Tue, 5 Nov 2019 12:50:27 +0100 Subject: [PATCH] SplitString() --- http.go | 12 ++++++++++++ string_util.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/http.go b/http.go index 6978e45..854de95 100644 --- a/http.go +++ b/http.go @@ -154,3 +154,15 @@ func InternalServerError(w http.ResponseWriter, r *http.Request, err string) { SetContentType(w, "application/json") Error(w, r, http.StatusInternalServerError, err) } + +func SetHeader(r *http.Request, key, val string) { + r.Header.Set(key, val) +} + +func AddHeader(r *http.Request, key, val string) { + r.Header.Add(key, val) +} + +func GetHeader(r *http.Request, key string) string { + return r.Header.Get(key) +} diff --git a/string_util.go b/string_util.go index 51f1d1c..d495248 100644 --- a/string_util.go +++ b/string_util.go @@ -92,6 +92,16 @@ func StringSliceContains(slice []string, s string) bool { return false } +func SplitString(s, sep string) (res []string) { + parts := strings.Split(s, sep) + for _, p := range parts { + if p != "" { + res = append(res, p) + } + } + return res +} + // StringAt ... func StringAt(s string, index int) string { if len(s)-1 < index || index < 0 { -- 1.8.1.2