util.go 587 B

1234567891011121314151617181920212223242526272829303132
  1. package util
  2. import (
  3. "gorm.io/gorm"
  4. "strconv"
  5. "strings"
  6. )
  7. var httpHead string
  8. type result struct {
  9. ID string
  10. }
  11. func GetNextId(db *gorm.DB, tableName string) string {
  12. var res result
  13. db.Table(tableName).Order("create_time desc").Select("id").Last(&res)
  14. strSlice := strings.Split(res.ID, "_")
  15. num, _ := strconv.Atoi(strSlice[len(strSlice)-1:][0])
  16. num += 1
  17. strSlice = append(strSlice[:len(strSlice)-1], strconv.Itoa(num))
  18. resId := strings.Join(strSlice, "_")
  19. return resId
  20. }
  21. func GetHTTPHead() string {
  22. return httpHead
  23. }
  24. func SetHTTPHead(head string) {
  25. httpHead = head
  26. }