github.com/searKing/golang/go@v1.2.74/util/object/string.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package object
     6  
     7  import (
     8  	"fmt"
     9  	"strings"
    10  )
    11  
    12  // Returns the result of calling {@code toString} on the first
    13  // argument if the first argument is not {@code null} and returns
    14  // the second argument otherwise.
    15  func ToString(o interface{}, nullDefault ...string) string {
    16  	if o == nil && nullDefault != nil && len(nullDefault) != 0 {
    17  		return strings.Join(nullDefault, "")
    18  	}
    19  	return fmt.Sprintf("%v", o)
    20  }