github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/project.go (about) 1 package models 2 3 import ( 4 "crypto/sha256" 5 "encoding/hex" 6 7 "github.com/machinefi/w3bstream/pkg/depends/base/types" 8 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/datatypes" 9 _ "github.com/machinefi/w3bstream/pkg/depends/util/strfmt" 10 "github.com/machinefi/w3bstream/pkg/enums" 11 ) 12 13 // Project schema for project information 14 // @def primary ID 15 // @def unique_index UI_project_id ProjectID 16 // @def unique_index UI_name Name 17 // 18 //go:generate toolkit gen model Project --database DB 19 type Project struct { 20 datatypes.PrimaryID 21 RelProject 22 RelAccount 23 ProjectName 24 ProjectBase 25 datatypes.OperationTimesWithDeleted 26 } 27 28 type RelProject struct { 29 ProjectID types.SFID `db:"f_project_id" json:"projectID"` 30 } 31 32 type ProjectName struct { 33 Name string `db:"f_name" json:"name" validate:"@projectName"` // Name project name 34 } 35 36 type ProjectBase struct { 37 Public datatypes.Bool `db:"f_public,default='2'" json:"public,omitempty"` // Public is true, project receive event from anonymous publisher 38 Version string `db:"f_version,default=''" json:"version,omitempty"` // Version project version 39 Proto enums.Protocol `db:"f_proto,default='0'" json:"protocol,omitempty"` // Proto project protocol for event publisher 40 Description string `db:"f_description,default=''" json:"description,omitempty"` 41 } 42 43 func (m Project) DatabaseName() string { 44 return "w3b_" + m.ProjectID.String() 45 } 46 47 func (m Project) Privileges() (usename, passwd string) { 48 usename = m.DatabaseName() 49 passwd = hex.EncodeToString(sha256.New().Sum([]byte(m.ProjectID.String()))) 50 return 51 }