0

I'm using the "Google APIs Client Library for Go" ( https://github.com/googleapis/google-api-go-client ) and it has an issue supporting the Slides API where a zero-based index request property is required but the struct definition indicates omitempty so zero values are omitted. I want to fork and modify this code to remove the omitempty values.

The specific code is here:

https://github.com/googleapis/google-api-go-client/blob/master/slides/v1/slides-gen.go#L4060-L4069

type Range struct {
    // EndIndex: The optional zero-based index of the end of the
    // collection.
    // Required for `FIXED_RANGE` ranges.
    EndIndex int64 `json:"endIndex,omitempty"`

    // StartIndex: The optional zero-based index of the beginning of the
    // collection.
    // Required for `FIXED_RANGE` and `FROM_START_INDEX` ranges.
    StartIndex int64 `json:"startIndex,omitempty"`

I've posted this topic here issue 433, but I'd also like to fork and modify the code to overcome this.

I run into the following issues when attempting to fork and modify this code.

First, it expects to only be imported using its original package name using the following package definition comment.

package slides // import "google.golang.org/api/slides/v1"

This comment results in the following error when attempting to use a fork:

code in directory /path/to/fork/google-api-go-client/slides/v1 expects import "google.golang.org/api/slides/v1"

Removing the comment from the package definition line allows the package to be loaded but then the following error is encountered which indicates an internal library is needed.

use of internal package google.golang.org/api/internal/gensupport not allowed

Is there any way to fork and modify this code?

Update

I was able to overcome the internal package issue with the following from Clive Makamara here.

$ ln -s /path/to/fork/google-api-go-client $GOPATH/google.golang.org/api

Unfortunately, this doesn't fully resolve the issue as other range types require the fields to be omitted, resulting in the following error:

googleapi: Error 400: Invalid requests[5].createParagraphBullets: The textRange startIndex must not be specified for range type ALL, badRequest

Since some range types require StartIndex and others require it to not be present, it seems like having separate range structs may be necessary.

My current workaround is to use the client as-is but add a small font size newline prefix so that I never have to update a text range starting at index 0.

Grokify
  • 15,092
  • 6
  • 60
  • 81
  • 1
    Possible duplicate of [Using forked package import in Go](https://stackoverflow.com/questions/14323872/using-forked-package-import-in-go). – Charlie Tumahai Dec 03 '19 at 08:30

1 Answers1

0

If you wish to fork the repository you can do it straight from github UI. Go the github repository and in the top right of the repository there is a Fork button:

Fork example

If you think your change is significant for the Google API maybe you could modify and do a pull request, look the project guidelines.

You can also take a look at the github Fork a Repo page for more information.

Raserhin
  • 2,516
  • 1
  • 10
  • 14
  • I was able to fork the repo, the issue was using Go "internal" packages. I resolved the internal package issue using the symbolic link approach above, but still ran into issues. It seems like 2 separate structs may be necessary but this may not be that straight-forward here given the different requirements per request property value. – Grokify Dec 03 '19 at 08:54