1234567891011121314151617181920212223242526272829303132 |
- package util
- import (
- "gorm.io/gorm"
- "strconv"
- "strings"
- )
- var httpHead string
- type result struct {
- ID string
- }
- func GetNextId(db *gorm.DB, tableName string) string {
- var res result
- db.Table(tableName).Order("create_time desc").Select("id").Last(&res)
- strSlice := strings.Split(res.ID, "_")
- num, _ := strconv.Atoi(strSlice[len(strSlice)-1:][0])
- num += 1
- strSlice = append(strSlice[:len(strSlice)-1], strconv.Itoa(num))
- resId := strings.Join(strSlice, "_")
- return resId
- }
- func GetHTTPHead() string {
- return httpHead
- }
- func SetHTTPHead(head string) {
- httpHead = head
- }
|