Files
gomoku/server/pkg/strings/strings.go
T
tiennm99 1b9eec5f7d refactor: rename Go module and copy core pkgs into server/pkg
- Module: github.com/ratel-online/server → github.com/tiennm99/gomoku/server
- Copied core/{log,util/async,util/json,util/strings,model,network,protocol,consts}
  into server/pkg/* (temporary shims until phase-05 replaces protocol/network)
- Rewrote all ratel-online import paths across server/**/*.go
- Trimmed main.go: single -p flag, WS-only on :1999, no TCP/bot/static
- Trimmed network/wss.go: endpoint /gomoku, no static file serving
- Updated Makefile: removed TCP/bot references, port 1999
2026-04-11 12:04:03 +07:00

94 lines
2.1 KiB
Go

package strings
import (
"encoding/json"
"strconv"
"strings"
)
func String(dest interface{}) string {
var key string
if dest == nil {
return key
}
switch dest.(type) {
case float64:
key = strconv.FormatFloat(dest.(float64), 'f', -1, 64)
case *float64:
key = strconv.FormatFloat(*dest.(*float64), 'f', -1, 64)
case float32:
key = strconv.FormatFloat(float64(dest.(float32)), 'f', -1, 32)
case *float32:
key = strconv.FormatFloat(float64(*dest.(*float32)), 'f', -1, 32)
case int:
key = strconv.Itoa(dest.(int))
case *int:
key = strconv.Itoa(*dest.(*int))
case uint:
key = strconv.Itoa(int(dest.(uint)))
case *uint:
key = strconv.Itoa(int(*dest.(*uint)))
case int8:
key = strconv.Itoa(int(dest.(int8)))
case *int8:
key = strconv.Itoa(int(*dest.(*int8)))
case uint8:
key = strconv.Itoa(int(dest.(uint8)))
case *uint8:
key = strconv.Itoa(int(*dest.(*uint8)))
case int16:
key = strconv.Itoa(int(dest.(int16)))
case *int16:
key = strconv.Itoa(int(*dest.(*int16)))
case uint16:
key = strconv.Itoa(int(dest.(uint16)))
case *uint16:
key = strconv.Itoa(int(*dest.(*uint16)))
case int32:
key = strconv.Itoa(int(dest.(int32)))
case *int32:
key = strconv.Itoa(int(*dest.(*int32)))
case uint32:
key = strconv.Itoa(int(dest.(uint32)))
case *uint32:
key = strconv.Itoa(int(*dest.(*uint32)))
case int64:
key = strconv.FormatInt(dest.(int64), 10)
case *int64:
key = strconv.FormatInt(*dest.(*int64), 10)
case uint64:
key = strconv.FormatUint(dest.(uint64), 10)
case *uint64:
key = strconv.FormatUint(*dest.(*uint64), 10)
case string:
key = dest.(string)
case *string:
key = *dest.(*string)
case []byte:
key = string(dest.([]byte))
case *[]byte:
key = string(*dest.(*[]byte))
case bool:
if dest.(bool) {
key = "true"
} else {
key = "false"
}
case *bool:
if *dest.(*bool) {
key = "true"
} else {
key = "false"
}
default:
newValue, _ := json.Marshal(dest)
key = string(newValue)
}
return key
}
func Desensitize(str string) string {
// Placeholder — original had Chinese word substitutions not relevant to gomoku.
return strings.TrimSpace(str)
}