Compare commits
2 Commits
895c4cd436
...
31c4249129
Author | SHA1 | Date | |
---|---|---|---|
31c4249129 | |||
d90736b1b6 |
@ -1,16 +1,14 @@
|
||||
#### ALL THE BADGES: GIT
|
||||
|
||||
![Build Check Runner](https://git.dragse.it/anthrove/otter-space-sdk/actions/workflows/build_check.yaml/badge.svg)
|
||||
|
||||
#### ALL THE BADGES: SONARQUBE
|
||||
|
||||
[![Bugs](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=bugs&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Code Smells](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=code_smells&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Coverage](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=coverage&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
|
||||
[![Duplicated Lines (%)](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=duplicated_lines_density&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Lines of Code](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=ncloc&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Maintainability Rating](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=sqale_rating&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Quality Gate Status](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=alert_status&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
|
||||
[![Reliability Rating](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=reliability_rating&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Security Hotspots](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=security_hotspots&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
[![Security Rating](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=security_rating&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
|
||||
|
@ -7,27 +7,26 @@ import (
|
||||
)
|
||||
|
||||
type ID interface {
|
||||
AnthroveUserID
|
||||
AnthroveSourceID
|
||||
AnthrovePostID
|
||||
AnthroveUserID | AnthroveSourceID | AnthrovePostID
|
||||
}
|
||||
|
||||
type BaseModel struct {
|
||||
ID string `gorm:"primaryKey"`
|
||||
type BaseModel[T ID] struct {
|
||||
ID T `gorm:"primaryKey"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
}
|
||||
|
||||
func (base *BaseModel) BeforeCreate(db *gorm.DB) error {
|
||||
func (base *BaseModel[T]) BeforeCreate(db *gorm.DB) error {
|
||||
var defaultVar T
|
||||
|
||||
if base.ID == "" {
|
||||
if base.ID == defaultVar {
|
||||
id, err := gonanoid.New(25)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
base.ID = id
|
||||
base.ID = T(id)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user