feat: publish standalone worker

Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
Gleb Tv
2026-07-13 17:55:14 +03:00
Коммит 2c7a0236da
309 изменённых файлов: 44004 добавлений и 0 удалений

41
app/models/concerns/has_token.go Обычный файл
Просмотреть файл

@@ -0,0 +1,41 @@
// Package concerns provides functionality.
package concerns
import (
"bytes"
"crypto/rand"
"encoding/base64"
)
// HasToken provides functionality.
type HasToken struct {
Token string `json:"-" gorm:"unique_index"`
}
// SetToken provides functionality.
func (m *HasToken) SetToken() {
tk := RandomToken(32)
m.Token = base64.RawURLEncoding.EncodeToString(tk)
if m.Token == "" {
panic("RandomToken failed: token not set")
}
if len(m.Token) < 32 {
panic("RandomToken failed: token too short")
}
}
// RandomToken provides functionality.
func RandomToken(tokenLen int) []byte {
b := make([]byte, tokenLen)
n, err := rand.Read(b)
if err != nil {
panic(err)
}
if n != tokenLen {
panic("RandomToken failed: bad len")
}
if bytes.Equal(b, make([]byte, tokenLen)) {
panic("RandomToken failed: generated empty token")
}
return b
}