path.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode
  3. import (
  4. "context"
  5. "net/http"
  6. "net/url"
  7. "github.com/sst/opencode-sdk-go/internal/apijson"
  8. "github.com/sst/opencode-sdk-go/internal/apiquery"
  9. "github.com/sst/opencode-sdk-go/internal/param"
  10. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  11. "github.com/sst/opencode-sdk-go/option"
  12. )
  13. // PathService contains methods and other services that help with interacting with
  14. // the opencode API.
  15. //
  16. // Note, unlike clients, this service does not read variables from the environment
  17. // automatically. You should not instantiate this service directly, and instead use
  18. // the [NewPathService] method instead.
  19. type PathService struct {
  20. Options []option.RequestOption
  21. }
  22. // NewPathService generates a new service that applies the given options to each
  23. // request. These options are applied after the parent client's options (if there
  24. // is one), and before any request-specific options.
  25. func NewPathService(opts ...option.RequestOption) (r *PathService) {
  26. r = &PathService{}
  27. r.Options = opts
  28. return
  29. }
  30. // Get the current path
  31. func (r *PathService) Get(ctx context.Context, query PathGetParams, opts ...option.RequestOption) (res *Path, err error) {
  32. opts = append(r.Options[:], opts...)
  33. path := "path"
  34. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  35. return
  36. }
  37. type Path struct {
  38. Config string `json:"config,required"`
  39. Directory string `json:"directory,required"`
  40. State string `json:"state,required"`
  41. Worktree string `json:"worktree,required"`
  42. JSON pathJSON `json:"-"`
  43. }
  44. // pathJSON contains the JSON metadata for the struct [Path]
  45. type pathJSON struct {
  46. Config apijson.Field
  47. Directory apijson.Field
  48. State apijson.Field
  49. Worktree apijson.Field
  50. raw string
  51. ExtraFields map[string]apijson.Field
  52. }
  53. func (r *Path) UnmarshalJSON(data []byte) (err error) {
  54. return apijson.UnmarshalRoot(data, r)
  55. }
  56. func (r pathJSON) RawJSON() string {
  57. return r.raw
  58. }
  59. type PathGetParams struct {
  60. Directory param.Field[string] `query:"directory"`
  61. }
  62. // URLQuery serializes [PathGetParams]'s query parameters as `url.Values`.
  63. func (r PathGetParams) URLQuery() (v url.Values) {
  64. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  65. ArrayFormat: apiquery.ArrayQueryFormatComma,
  66. NestedFormat: apiquery.NestedQueryFormatBrackets,
  67. })
  68. }