mirror of
https://github.com/holos-run/holos.git
synced 2026-03-20 17:25:01 +00:00
This patch refactors the API following the [API Best Practices][api] documentation. The UpdatePlatform method is modeled after a mutating operation described [by Netflix][nflx] instead of using a REST resource representation. This makes it much easier to iterate over the fields that need to be updated as the PlatformUpdateOperation is a flat data structure while a Platform resource may have nested fields. Nested fields are more complicated and less clear to handle with a FieldMask. This patch also adds a snapckbar message on save. Previously, the save button didn't give any indication of success or failure. This patch fixes the problem by adding a snackbar message that pop up at the bottom of the screen nicely. When the snackbar message is dismissed or times out the save button is re-enabled. [api]: https://protobuf.dev/programming-guides/api/ [nflx]: https://netflixtechblog.com/practical-api-design-at-netflix-part-2-protobuf-fieldmask-for-mutation-operations-2e75e1d230e4 Examples: FieldMask for ListPlatforms ``` grpcurl -H "x-oidc-id-token: $(holos token)" -d @ ${HOLOS_SERVER##*/} holos.platform.v1alpha1.PlatformService.ListPlatforms <<EOF { "org_id": "018f36fb-e3f7-7f7f-a1c5-c85fb735d215", "field_mask": { "paths": ["id","name"] } } EOF ``` ```json { "platforms": [ { "id": "018f36fb-e3ff-7f7f-a5d1-7ca2bf499e94", "name": "bare" }, { "id": "018f6b06-9e57-7223-91a9-784e145d998c", "name": "gary" }, { "id": "018f6b06-9e53-7223-8ae1-1ad53d46b158", "name": "jeff" }, { "id": "018f6b06-9e5b-7223-8b8b-ea62618e8200", "name": "nate" } ] } ``` Closes: #171
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
// Copyright 2010 The Go Authors. All rights reserved.
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are
|
|
// met:
|
|
//
|
|
// - Redistributions of source code must retain the above copyright
|
|
// notice, this list of conditions and the following disclaimer.
|
|
//
|
|
// - Redistributions in binary form must reproduce the above
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
// in the documentation and/or other materials provided with the
|
|
// distribution.
|
|
//
|
|
// - Neither the name of Google Inc. nor the names of its
|
|
// contributors may be used to endorse or promote products derived from
|
|
// this software without specific prior written permission.
|
|
//
|
|
// Original license: https://github.com/golang/protobuf/blob/master/LICENSE
|
|
// Original CamelCase func: https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go#L2648
|
|
|
|
package strings
|
|
|
|
// CamelCase is a special case of PascalCase with the difference that
|
|
// CamelCase will return the first value in the string as a lowercase character.
|
|
// In short, _my_field_name_2 becomes xMyFieldName_2.
|
|
func CamelCase(s string) string {
|
|
if s == "" {
|
|
return ""
|
|
}
|
|
t := make([]byte, 0, 32)
|
|
i := 0
|
|
if s[0] == '_' {
|
|
// Need a capital letter; drop the '_'.
|
|
t = append(t, 'x')
|
|
i++
|
|
}
|
|
// If the first letter is a lowercase, we keep it as is.
|
|
if len(t) == 0 && isASCIILower(s[i]) {
|
|
t = append(t, s[i])
|
|
t, i = appendLowercaseSequence(s, i, t)
|
|
i++
|
|
}
|
|
return string(append(t, lookupAndReplacePascalCaseWords(s, i)...))
|
|
}
|