drive_view.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Code generated by tailscale/cmd/viewer; DO NOT EDIT.
  4. package drive
  5. import (
  6. jsonv1 "encoding/json"
  7. "errors"
  8. jsonv2 "github.com/go-json-experiment/json"
  9. "github.com/go-json-experiment/json/jsontext"
  10. "tailscale.com/types/views"
  11. )
  12. //go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type=Share
  13. // View returns a read-only view of Share.
  14. func (p *Share) View() ShareView {
  15. return ShareView{ж: p}
  16. }
  17. // ShareView provides a read-only view over Share.
  18. //
  19. // Its methods should only be called if `Valid()` returns true.
  20. type ShareView struct {
  21. // ж is the underlying mutable value, named with a hard-to-type
  22. // character that looks pointy like a pointer.
  23. // It is named distinctively to make you think of how dangerous it is to escape
  24. // to callers. You must not let callers be able to mutate it.
  25. ж *Share
  26. }
  27. // Valid reports whether v's underlying value is non-nil.
  28. func (v ShareView) Valid() bool { return v.ж != nil }
  29. // AsStruct returns a clone of the underlying value which aliases no memory with
  30. // the original.
  31. func (v ShareView) AsStruct() *Share {
  32. if v.ж == nil {
  33. return nil
  34. }
  35. return v.ж.Clone()
  36. }
  37. // MarshalJSON implements [jsonv1.Marshaler].
  38. func (v ShareView) MarshalJSON() ([]byte, error) {
  39. return jsonv1.Marshal(v.ж)
  40. }
  41. // MarshalJSONTo implements [jsonv2.MarshalerTo].
  42. func (v ShareView) MarshalJSONTo(enc *jsontext.Encoder) error {
  43. return jsonv2.MarshalEncode(enc, v.ж)
  44. }
  45. // UnmarshalJSON implements [jsonv1.Unmarshaler].
  46. func (v *ShareView) UnmarshalJSON(b []byte) error {
  47. if v.ж != nil {
  48. return errors.New("already initialized")
  49. }
  50. if len(b) == 0 {
  51. return nil
  52. }
  53. var x Share
  54. if err := jsonv1.Unmarshal(b, &x); err != nil {
  55. return err
  56. }
  57. v.ж = &x
  58. return nil
  59. }
  60. // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
  61. func (v *ShareView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
  62. if v.ж != nil {
  63. return errors.New("already initialized")
  64. }
  65. var x Share
  66. if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
  67. return err
  68. }
  69. v.ж = &x
  70. return nil
  71. }
  72. // Name is how this share appears on remote nodes.
  73. func (v ShareView) Name() string { return v.ж.Name }
  74. // Path is the path to the directory on this machine that's being shared.
  75. func (v ShareView) Path() string { return v.ж.Path }
  76. // As is the UNIX or Windows username of the local account used for this
  77. // share. File read/write permissions are enforced based on this username.
  78. // Can be left blank to use the default value of "whoever is running the
  79. // Tailscale GUI".
  80. func (v ShareView) As() string { return v.ж.As }
  81. // BookmarkData contains security-scoped bookmark data for the Sandboxed
  82. // Mac application. The Sandboxed Mac application gains permission to
  83. // access the Share's folder as a result of a user selecting it in a file
  84. // picker. In order to retain access to it across restarts, it needs to
  85. // hold on to a security-scoped bookmark. That bookmark is stored here. See
  86. // https://developer.apple.com/documentation/security/app_sandbox/accessing_files_from_the_macos_app_sandbox#4144043
  87. func (v ShareView) BookmarkData() views.ByteSlice[[]byte] {
  88. return views.ByteSliceOf(v.ж.BookmarkData)
  89. }
  90. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
  91. var _ShareViewNeedsRegeneration = Share(struct {
  92. Name string
  93. Path string
  94. As string
  95. BookmarkData []byte
  96. }{})