-
Notifications
You must be signed in to change notification settings - Fork 7
/
general.go
36 lines (30 loc) · 936 Bytes
/
general.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package gostrutils
import "net/http"
// DetectMimeTypeFromContent takes a slice of bytes, and try to detect the
// content type that is in use.
func DetectMimeTypeFromContent(content []byte) (contentType string) {
contentType = http.DetectContentType(content)
return
}
// StrToPointer returns the address of string.
//
// The function can help when there is a need to convert literal string yo be
// have a pointer for that content.
func StrToPointer(str string) *string {
return &str
}
// PointerToStr converts a pointer string to a normal string
//
// If there is a need for a string to be nil, then usually there is a pointer
// for a string involved. The current function converts nil pointer to empty
// string, or return the string itself
func PointerToStr(s *string) string {
if s == nil {
return ""
}
return *s
}
// ByteToStr converts slice of bytes to string
func ByteToStr(b []byte) string {
return string(b)
}