opts.go
func GoogleServiceAccountCredentialsJSON(buf []byte) Option {
	return func(sh *StackdriverHook) error {
		var err error

		// load credentials
		gsa, err := gserviceaccount.FromJSON(buf)
		if err != nil {
			return err
		}

		// check project id
		if gsa.ProjectID == "" {
			return errors.New("google service account credentials missing project_id")
		}

		// set project id
		err = ProjectID(gsa.ProjectID)(sh)
		if err != nil {
			return err
		}

		// set resource type
		err = Resource(ResTypeProject, map[string]string{
			"project_id": gsa.ProjectID,
		})(sh)
		if err != nil {
			return err
		}

		// create token source
		ts, err := gsa.TokenSource(nil, requiredScopes...)
		if err != nil {
			return err
		}

		// set client
		return HTTPClient(&http.Client{
			Transport: &oauth2.Transport{
				Source: oauth2.ReuseTokenSource(nil, ts),
			},
		})(sh)
	}
}
func GoogleServiceAccountCredentialsJSON(buf []byte) Option {
	return func(sh *StackdriverHook) error {
		var err error

		// load credentials
		gsa, err := gserviceaccount.FromJSON(buf)
		if err != nil {
			return err
		}

		// check project id
		if gsa.ProjectID == "" {
			return errors.New("google service account credentials missing project_id")
		}

		// set project id
		err = ProjectID(gsa.ProjectID)(sh)
		if err != nil {
			return err
		}

		// set resource type
		err = Resource(ResTypeProject, map[string]string{
			"project_id": gsa.ProjectID,
		})(sh)
		if err != nil {
			return err
		}

		// create token source
		ts, err := gsa.TokenSource(nil, requiredScopes...)
		if err != nil {
			return err
		}

		// set client
		return HTTPClient(&http.Client{
			Transport: &oauth2.Transport{
				Source: oauth2.ReuseTokenSource(nil, ts),
			},
		})(sh)
	}
}
// GoogleServiceAccountCredentialsJSON is an option that creates the
// Stackdriver logging service using the supplied Google service account
// credentials.
//
// Google Service Account credentials can be downloaded from the Google Cloud
// console: https://console.cloud.google.com/iam-admin/serviceaccounts/