I'm testing this small code fragment using miniredis mock for Redis. repository.client is a functioning mock (used for other tests) that returns a Redis client.
err := repository.client.Publish(ctx, "UPDATE", "MESSAGE").Err()
if err != nil {
log.fatal(err.Error())
}
When I run the test it logs me the following error:
ERR unknown command `publish`, with args beginning with: `UPDATES`, `MESSAGE`,
I'm confused by the fact that miniredis should implement pub-sub functionalities. Any clue of what is the issue?
After researching on owner's repository I found out that the issue was related to the imported version. In online articles, it is normally cited the import github.com/alicebob/miniredis, but it doesn't have implemented pub/sub functionalities. To make them work it is important to import V2:
github.com/alicebob/miniredis/v2
Source: https://github.com/alicebob/miniredis/issues/157
Related
I'm trying to setup the storage emulator for my firebase project. I am using the Go admin sdk. However it seems to be ignored despite following the documented process.
App initialization:
func App(ctx context.Context) (*firebase.App, error) {
opt := option.WithCredentialsFile("firebase-service-account.json")
config := firebase.Config{
StorageBucket: "<my-project-id>.appspot.com",
}
app, err := firebase.NewApp(ctx, &config, opt)
if err != nil {
return nil, fmt.Errorf("error initializing app: %v", err)
}
return app, nil
}
.env file loaded on startup:
FIRESTORE_EMULATOR_HOST="localhost:8081"
FIREBASE_STORAGE_EMULATOR_HOST="localhost:9199"
GCLOUD_PROJECT="my-project-id"
I also tried manually setting these by running:
export FIREBASE_STORAGE_EMULATOR_HOST="localhost:9199" and export GCLOUD_PROJECT="my-project-id".
However, when when writing to the default bucket, my blob appears in the actual firestore console for storage, not the storage emulator.
I pulled the GCLOUD_PROJECT value from my service account json file, the project_id field specifically. Also confirmed that 9199 is the port that storage is running on.
Besides setting those FIREBASE_STORAGE_EMULATOR_HOST and GCLOUD_PROJECT am I missing something else?
The variable name is STORAGE_EMULATOR_HOST.
See: https://pkg.go.dev/cloud.google.com/go/storage
Firebaser Here,
You're correct in that your current setup should have been sufficient. I've filed an issue in the GO SDK Repo so that this can get addressed.
In the meanwhile the current fix, as #mabg pointed out, is to set the STORAGE_EMULATOR_HOST variable as well Code Sample
I'm new to firebase and I'm trying to setup a small test with a simple database in Go.
I struggle a lot with the database connection. Here is my code:
tx := context.Background()
conf := &firebase.Config{
DatabaseURL: "https://mydb.europe-west1.firebasedatabase.app",
}
// Fetch the service account key JSON file contents
opt := option.WithCredentialsFile("./fireBasePrivateKey.json")
// Initialize the app with a service account, granting admin privileges
app, err := firebase.NewApp(ctx, conf, opt)
if err != nil {
log.Fatalln("Error initializing app:", err)
}
client, err := app.Database(ctx)
if err != nil {
log.Fatalln("Error initializing database client:", err)
}
With that code (which comes from the official documentation), I've got an error on the Database client initialization:
invalid database url: wants host: .firebaseio.com
I then tried with the requested url: mydb.firebaseio.com -> I've got another error telling me my db is not in that region and gives me the previous db address.
I also tried other things like mydb.europe-west1.firebaseio.com but here it says me the certificate is not valid for this url...
I'm a bit lost. I understand the problem has to do with the localization of the DB I choose when I created it, but I don't understand how to handle it with the go implementation.
The <projectname>.firebaseio.com format used to be the only format for Firebase Database URLs until early last year. Nowadays, databases in the US still use that format, but databases in other regions use the <dbname><region>.firebasedatabase.app format that you have.
Support for the newer URL format was added in PR #423 and released in version 4.6 of the Go Admin SDK, which was released in June. Upgrade to this version (or later), to ensure you don't get the error message anymore.
Now I have a Golang Application deployed on GAE, with stackdriver trace.
About stackdriver Trace, to get custom span data, I did set up on my code, like
exporter, err := stackdriver.NewExporter(stackdriver.Options{
ProjectID: os.Getenv("GOOGLE_CLOUD_PROJECT"),
})
if err != nil {
log.Fatal(err)
}
trace.RegisterExporter(exporter)
client := &http.Client{
Transport: &ochttp.Transport{
// Use Google Cloud propagation format.
Propagation: &propagation.HTTPFormat{},
},
}
ref. https://cloud.google.com/trace/docs/setup/go
On GAE, I succeed in viewing trace on my GCP console.
but, I DON'T want to trace these log on my local developing environment (I'm using docker).currently, I try to run my application on docker, nil pointer panic shows up on Span.Export() which may be called from Span.End().
So, I wonder if someone knows the way to DISABLE stackdriver trace on specific environment (with my case, on docker).
Otherwise, should I check condition of trace configuration, like as below ?
if trace.projectId != "" {
ctx := reque.Context()
_, span := trace.StartSpan(ctx,"Span blahblah")
defer span.End()
}
There is no point for Google in adding an extra logic like you need into the Trace code, the GAE apps are instrumented with, in order to disable that Trace code when the GAE App is executed somewhere in a third party environment like Docker on-prem. Most likely an answer to the question is "No, there is no magic config for that". Hence it is up-to-you how to sort this out.
As a general idea: following up an approach with [NoopExporter] offered by Emile Pels and having admitted the fact we can't get rid of the Trace code with "magic config", if I developed my app in Python I'd considered using decorator as a wrapper to bring piece of intelligence into the Trace calls, or redefining them as mock functions. It seems Golang does not have direct analog of Python decorators but this functionality could be implemented somehow. This is being discussed in the Internet, for example here:
Go Decorator Function Pattern
Redefine function so that it references its own self
I am fairly new to the Go programming language and completely new to the Go SDK from AWS. I am trying to use a service but I have a strange problem where the types defined by the imported service are found, but the functions of the service are undefined.
This question is not about using the particular service, but just how to correctly import it. My code:
package auth
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
)
func SignUpTest() {
input := cognitoidentityprovider.SignUpInput{
Username: aws.String("example#mail.com"),
Password: aws.String("test1234"),
}
_, err := cognitoidentityprovider.SignUp(&input)
if err != nil {
log.Fatal(err)
}
}
I get the following error when running go build:
auth/signup.go:18:12: undefined: cognitoidentityprovider.SignUp
The autocomplete in my IDE also states that it can find the cognitoidentityprovider.SingUpInput struct, but it is unable to find the cognitoidentityprovider.SignUp function.
I use Go 1.10.1 on WSL Ubuntu. I use DEP 0.4.1 for package management. I verified that the AWS SDK is available in the vendor folder and that the cognitoidentityprovider package is available (the SignUp) function is also there.
What am I missing here?
The error says it all. cognitoidentityprovider.SignUp isn't defined, because there is no symbol SignUp exported by the cognitoidentityprovider package.
I'm not really sure what you want to do instead, since I'm not familiar with that SDK, but you're trying to call a function that doesn't exist. I suggest re-examining the documentation or example you're following. You've probably made a simple mistake.
You seem to be confused by the CognitoIdentityProvider.SignUp instance method. But as that's an instance method, and not an exported function, it requires an instance of a CognitoIdentityProvider first:
cip := cognitoidentityprovider.New( ... )
_, err := cip.SignUp(input)
I have a Go Application that needs to consume a GraphQL service, now the documentation of graphQL is more oriented to the GraphQL server and not as a client. How can I do that?
I checked this example but some things are not clear to me:
Should I have a Resolve function to each field that I am going to retrieve?
Should I have defined the variable 'fields' with the data structure that I am expecting?
Where can I find a very simple example of a GraphQL client in Golang?
You should check this project: https://github.com/machinebox/graphql .
If you don't want to use an external library inside in your project, you could look the code and see how can you implement a simple client.
One of the module that I would recommend is shurcool
client = graphql.NewClient("http://<<graphqlEndpoint>>", nil)
err := client.Query(context.Background(), &query, nil)
if err != nil {
// Handle error.
}
fmt.Println(query.Me.Name)