string.go 603 B

12345678910111213141516171819202122232425
  1. // Copyright 2022 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package dbutil
  5. import (
  6. "fmt"
  7. "gogs.io/gogs/internal/conf"
  8. )
  9. // Quote adds surrounding double quotes for all given arguments before being
  10. // formatted if the current database is UsePostgreSQL.
  11. func Quote(format string, args ...string) string {
  12. anys := make([]any, len(args))
  13. for i := range args {
  14. if conf.UsePostgreSQL {
  15. anys[i] = `"` + args[i] + `"`
  16. } else {
  17. anys[i] = args[i]
  18. }
  19. }
  20. return fmt.Sprintf(format, anys...)
  21. }