github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/sqlx/driver/postgres/opts.go (about)

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