-
Notifications
You must be signed in to change notification settings - Fork 9
/
permissionId.go
49 lines (41 loc) · 972 Bytes
/
permissionId.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package attrs
import (
"context"
"fmt"
"github.com/PGSSoft/terraform-provider-mssql/internal/sql"
"github.com/hashicorp/terraform-plugin-framework/attr"
)
func PermissionIdType[T sql.NumericObjectId]() attr.Type {
var t attr.Type
t = permissionIdType[T]{
compositeIdType{
elemCount: 2,
valueFactory: func(id CompositeId) attr.Value {
id.attrType = &t
return PermissionId[T]{id}
},
},
}
return t
}
type permissionIdType[T sql.NumericObjectId] struct {
compositeIdType
}
func PermissionIdValue[T sql.NumericObjectId](id T, permission string) PermissionId[T] {
t := PermissionIdType[T]()
return PermissionId[T]{
CompositeId{
attrType: &t,
elems: []string{fmt.Sprint(id), permission},
},
}
}
type PermissionId[T sql.NumericObjectId] struct {
CompositeId
}
func (id PermissionId[T]) ObjectId(ctx context.Context) T {
return T(id.GetInt(ctx, 0))
}
func (id PermissionId[T]) Permission() string {
return id.GetString(1)
}