Skip to content

How to use a client object other than the defaultClient? #5

Description

@junpayment

Hi,

It seems that the defaultClient is present in the parse package as a singleton.

https://github.com/kylemcc/parse/blob/master/rest.go#L75

var defaultClient *clientT

// Initialize the parse library with your API keys
func Initialize(appId, restKey, masterKey string) {
    defaultClient = &clientT{
        appId:      appId,
        restKey:    restKey,
        masterKey:  masterKey,
        userAgent:  "github.com/kylemcc/parse",
        httpClient: &http.Client{},
    }
}

Therefore, for example, if I want to access multiple parse endpoints, it seems to be necessary to initialize each time, like below.

func (cli *ParseClient) initParseClient() {
	parse.Initialize(cli.appId, cli.restKey, cli.masterKey)
	parse.ServerURL(cli.serverUrl)
}

func (cli *ParseClient) NewQuery(m interface{}) (parse.Query, error) {
	cli.initParseClient()
	query, err := parse.NewQuery(m)
	if err != nil {
		return nil, err
	}

	return query, nil
}

I would like to use multiple client objects, how can I do that?

Thanks your great product!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions