github.com/kunlun-qilian/sqlx/v3@v3.0.0/connectors/postgresql/opts.go (about)

     1  package postgresql
     2  
     3  import (
     4  	"bytes"
     5  	"sort"
     6  	"strings"
     7  )
     8  
     9  func FromConfigString(s string) PostgreSQLOpts {
    10  	opts := PostgreSQLOpts{}
    11  	for _, kv := range strings.Split(s, " ") {
    12  		kvs := strings.Split(kv, "=")
    13  		if len(kvs) > 1 {
    14  			opts[kvs[0]] = kvs[1]
    15  		}
    16  	}
    17  	return opts
    18  }
    19  
    20  type PostgreSQLOpts map[string]string
    21  
    22  func (opts PostgreSQLOpts) String() string {
    23  	buf := bytes.NewBuffer(nil)
    24  
    25  	kvs := make([]string, 0)
    26  	for k := range opts {
    27  		kvs = append(kvs, k)
    28  	}
    29  	sort.Strings(kvs)
    30  
    31  	for i, k := range kvs {
    32  		if i > 0 {
    33  			buf.WriteByte(' ')
    34  		}
    35  		buf.WriteString(k)
    36  		buf.WriteByte('=')
    37  		buf.WriteString(opts[k])
    38  	}
    39  
    40  	return buf.String()
    41  }