| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- // Copyright (c) Tailscale Inc & AUTHORS
- // SPDX-License-Identifier: BSD-3-Clause
- // Code generated by tailscale/cmd/viewer; DO NOT EDIT.
- package drive
- import (
- jsonv1 "encoding/json"
- "errors"
- jsonv2 "github.com/go-json-experiment/json"
- "github.com/go-json-experiment/json/jsontext"
- "tailscale.com/types/views"
- )
- //go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type=Share
- // View returns a read-only view of Share.
- func (p *Share) View() ShareView {
- return ShareView{ж: p}
- }
- // ShareView provides a read-only view over Share.
- //
- // Its methods should only be called if `Valid()` returns true.
- type ShareView struct {
- // ж is the underlying mutable value, named with a hard-to-type
- // character that looks pointy like a pointer.
- // It is named distinctively to make you think of how dangerous it is to escape
- // to callers. You must not let callers be able to mutate it.
- ж *Share
- }
- // Valid reports whether v's underlying value is non-nil.
- func (v ShareView) Valid() bool { return v.ж != nil }
- // AsStruct returns a clone of the underlying value which aliases no memory with
- // the original.
- func (v ShareView) AsStruct() *Share {
- if v.ж == nil {
- return nil
- }
- return v.ж.Clone()
- }
- // MarshalJSON implements [jsonv1.Marshaler].
- func (v ShareView) MarshalJSON() ([]byte, error) {
- return jsonv1.Marshal(v.ж)
- }
- // MarshalJSONTo implements [jsonv2.MarshalerTo].
- func (v ShareView) MarshalJSONTo(enc *jsontext.Encoder) error {
- return jsonv2.MarshalEncode(enc, v.ж)
- }
- // UnmarshalJSON implements [jsonv1.Unmarshaler].
- func (v *ShareView) UnmarshalJSON(b []byte) error {
- if v.ж != nil {
- return errors.New("already initialized")
- }
- if len(b) == 0 {
- return nil
- }
- var x Share
- if err := jsonv1.Unmarshal(b, &x); err != nil {
- return err
- }
- v.ж = &x
- return nil
- }
- // UnmarshalJSONFrom implements [jsonv2.UnmarshalerFrom].
- func (v *ShareView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
- if v.ж != nil {
- return errors.New("already initialized")
- }
- var x Share
- if err := jsonv2.UnmarshalDecode(dec, &x); err != nil {
- return err
- }
- v.ж = &x
- return nil
- }
- // Name is how this share appears on remote nodes.
- func (v ShareView) Name() string { return v.ж.Name }
- // Path is the path to the directory on this machine that's being shared.
- func (v ShareView) Path() string { return v.ж.Path }
- // As is the UNIX or Windows username of the local account used for this
- // share. File read/write permissions are enforced based on this username.
- // Can be left blank to use the default value of "whoever is running the
- // Tailscale GUI".
- func (v ShareView) As() string { return v.ж.As }
- // BookmarkData contains security-scoped bookmark data for the Sandboxed
- // Mac application. The Sandboxed Mac application gains permission to
- // access the Share's folder as a result of a user selecting it in a file
- // picker. In order to retain access to it across restarts, it needs to
- // hold on to a security-scoped bookmark. That bookmark is stored here. See
- // https://developer.apple.com/documentation/security/app_sandbox/accessing_files_from_the_macos_app_sandbox#4144043
- func (v ShareView) BookmarkData() views.ByteSlice[[]byte] {
- return views.ByteSliceOf(v.ж.BookmarkData)
- }
- // A compilation failure here means this code must be regenerated, with the command at the top of this file.
- var _ShareViewNeedsRegeneration = Share(struct {
- Name string
- Path string
- As string
- BookmarkData []byte
- }{})
|