package util

import (
	
	
	
	
	
)

// IsJSONType method is to check JSON content type or not
func ( string) bool {
	return strings.Contains(, "json")
}

// IsXMLType method is to check XML content type or not
func ( string) bool {
	return strings.Contains(, "xml")
}

// GetPointer return the pointer of the interface.
func ( any) any {
	 := reflect.TypeOf()
	if .Kind() == reflect.Ptr {
		if  := .Elem(); .Kind() == reflect.Ptr { // pointer of pointer
			if .Elem().Kind() == reflect.Ptr {
				panic("pointer of pointer of pointer is not supported")
			}
			 := reflect.ValueOf().Elem()
			if .IsZero() {
				 := reflect.New(.Elem())
				.Set()
				return .Interface()
			} else {
				return .Interface()
			}
		} else {
			if reflect.ValueOf().IsZero() {
				 := reflect.New(.Elem())
				return .Interface()
			}
			return 
		}
	}
	return reflect.New().Interface()
}

// GetType return the underlying type.
func ( any) reflect.Type {
	return reflect.Indirect(reflect.ValueOf()).Type()
}

// CutString slices s around the first instance of sep,
// returning the text before and after sep.
// The found result reports whether sep appears in s.
// If sep does not appear in s, cut returns s, "", false.
func (,  string) (,  string,  bool) {
	if  := strings.Index(, );  >= 0 {
		return [:], [+len():], true
	}
	return , "", false
}

// CutBytes slices s around the first instance of sep,
// returning the text before and after sep.
// The found result reports whether sep appears in s.
// If sep does not appear in s, cut returns s, nil, false.
//
// CutBytes returns slices of the original slice s, not copies.
func (,  []byte) (,  []byte,  bool) {
	if  := bytes.Index(, );  >= 0 {
		return [:], [+len():], true
	}
	return , nil, false
}

// IsStringEmpty method tells whether given string is empty or not
func ( string) bool {
	return len(strings.TrimSpace()) == 0
}

// See 2 (end of page 4) https://www.ietf.org/rfc/rfc2617.txt
// "To receive authorization, the client sends the userid and password,
// separated by a single colon (":") character, within a base64
// encoded string in the credentials."
// It is not meant to be urlencoded.
func basicAuth(,  string) string {
	 :=  + ":" + 
	return base64.StdEncoding.EncodeToString([]byte())
}

// BasicAuthHeaderValue return the header of basic auth.
func (,  string) string {
	return "Basic " + basicAuth(, )
}

// CreateDirectory create the directory.
func ( string) ( error) {
	if _,  = os.Stat();  != nil {
		if os.IsNotExist() {
			if  = os.MkdirAll(, 0755);  != nil {
				return
			}
		}
	}
	return
}