Mode:
Duration:
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
package main
import "fmt"
type IAMPolicy struct {
Resource string
Action string
}
type User struct {
Name string
Role string
Policy IAMPolicy
}
func checkAccess(user User, action string) bool {
return user.Policy.Action == action
}
func main() {
user := User{
Name: "api-service-user",
Role: "BackendRole",
Policy: IAMPolicy{
Resource: "Database",
Action: "Read",
},
}
fmt.Println("IAM User:", user.Name)
fmt.Println("IAM Role:", user.Role)
if checkAccess(user, "Read") {
fmt.Println("Access Granted")
} else {
fmt.Println("Access Denied")
}
}Coding works best on desktop or with an external keyboard.