infobloxopen / protoc-gen-gorm

A protobuf compiler plugin designed to generate GORM models and APIs for simple object persistence tasks.
Apache License 2.0
546 stars 161 forks source link

Readonly fields? #144

Closed molon closed 5 years ago

molon commented 5 years ago

There are readonly fields many time.

message Shop {
    option (gorm.opts) = {
        ormable: true,
        multi_account: true,
        include: [
            {type: "*time.Time", name: "deleted_at"} // this field is non-visible. it's ok.
        ]
    };

    string name = 4;

    // We want the fields below to be visible, but can't writable.
    string id = 1 [(gorm.field).tag = {primary_key: true}]; 
    google.protobuf.Timestamp created_at = 2;
    google.protobuf.Timestamp updated_at = 3;
}

I have tried this library. https://github.com/infobloxopen/protoc-gen-atlas-validate Then I cant assign the created_at field in request.payload. But~ the created_at was still be updated to empty. Because If I don't assign the created_at field, it will be transfer into request as empty value.

molon commented 5 years ago

And sometimes we need write-only fields. eg: password

molon commented 5 years ago

with the first question, I have used protoc-gen-atlas-validate and field_presence to solve it. But I disable the FieldMasks for gateway to prevent wrong usage(https://github.com/agilab/atlas-app-toolkit/commit/c2a67b5120c88db3acb51181a4021fcfd18579b3).

fi0 commented 5 years ago

@molon how did you create a password field? and probably the password_hash field?