path.go 2.4 KB

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