github.com/blend/go-sdk@v1.20220411.3/webutil/split_colon.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package webutil 9 10 import ( 11 "strings" 12 13 "github.com/blend/go-sdk/ex" 14 ) 15 16 // SplitColon splits a string on a **single** colon. For example, for a basic 17 // auth header, we'd want to split a string of the form "<username>:<password>". 18 func SplitColon(value string) (first, second string, err error) { 19 pair := strings.SplitN(value, ":", 2) 20 if len(pair) != 2 || pair[0] == "" || pair[1] == "" { 21 err = ex.New(ErrInvalidSplitColonInput, ex.OptMessagef("input: %q", value)) 22 return 23 } 24 first = pair[0] 25 second = pair[1] 26 return 27 }