string.go 802 B

1234567891011121314151617181920212223242526272829
  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 and LICENSE.gogs file.
  4. // Copyright 2025 Huan-Gogs Authors. All rights reserved.
  5. // Use of this source code is governed by a MIT-style
  6. // license that can be found in the LICENSE file.
  7. package dbutil
  8. import (
  9. "fmt"
  10. "github.com/SongZihuan/huan-gogs/internal/conf"
  11. )
  12. // Quote adds surrounding double quotes for all given arguments before being
  13. // formatted if the current database is UsePostgreSQL.
  14. func Quote(format string, args ...string) string {
  15. anys := make([]any, len(args))
  16. for i := range args {
  17. if conf.UsePostgreSQL {
  18. anys[i] = `"` + args[i] + `"`
  19. } else {
  20. anys[i] = args[i]
  21. }
  22. }
  23. return fmt.Sprintf(format, anys...)
  24. }