Files
masonry/examples/sdk/debug_sdk.go
Mason Payne 9b209dfe63 try an SDK and a manually defined lang
I don't think I like the SDK way, and langV2 seems to be so simialr to
V1 that I'm probably going to stick with V1 for now and see if i can get
it to do what I need.
2025-08-20 00:13:41 -06:00

137 lines
2.3 KiB
Go

package main
import (
"encoding/json"
"masonry/sdk"
)
func main() {
userEntity := sdk.Entity{
Name: "User",
Description: nil,
Fields: []sdk.Field{
{
Name: "id",
Type: "int",
Required: true,
Unique: true,
Default: nil,
Validations: []sdk.Validation{
{
Type: "validate",
Value: nil,
},
},
Relationship: nil,
},
{
Name: "username",
Type: "string",
Required: true,
Unique: true,
Default: nil,
Validations: []sdk.Validation{
{
Type: "validate",
Value: nil,
},
},
Relationship: nil,
},
{
Name: "email",
Type: "string",
Required: true,
Unique: true,
Default: nil,
Validations: []sdk.Validation{
{
Type: "validate",
Value: nil,
},
},
Relationship: nil,
},
{
Name: "password",
Type: "string",
Required: true,
Unique: false,
Default: nil,
Validations: []sdk.Validation{
{
Type: "validate",
Value: nil,
},
},
Relationship: nil,
},
{
Name: "created_at",
Type: "datetime",
Required: true,
Unique: false,
Default: nil,
Validations: []sdk.Validation{
{
Type: "validate",
Value: nil,
},
},
Relationship: nil,
},
{
Name: "updated_at",
Type: "datetime",
Required: true,
Unique: false,
Default: nil,
Validations: []sdk.Validation{
{
Type: "validate",
Value: nil,
},
},
Relationship: nil,
},
},
}
createUserDesc := "Create a new user with username, email, and password. Returns the created user object."
createUser := sdk.Endpoint{
Method: "POST",
Path: "/user",
Entity: userEntity,
Description: &createUserDesc,
Auth: true,
Permissions: nil,
}
server := sdk.Server{
Name: "TestServer",
Settings: []sdk.ServerSetting{
{
Host: "localhost",
Port: 8000,
},
},
Endpoints: []sdk.Endpoint{
createUser,
},
}
def := sdk.Definition{
Server: []sdk.Server{
server,
},
}
out, err := json.MarshalIndent(def, "", " ")
if err != nil {
panic(err)
}
println(string(out))
println("🎉 Successfully built SDK definition!")
println("You can now use this SDK definition in your application.")
}