firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.16k stars 248 forks source link

firebase admin sdk build error #504

Open hiteshkumar848 opened 2 years ago

hiteshkumar848 commented 2 years ago

Environment

Problem

Getting the following on running go build main.go vendor/github.com/firebase/firebase-admin-go/firebase.go:31:2: use of internal package firebase.google.com/go/internal not allowed

The error seems correct according to the document but then why is the internal package functions of firebase.google.com/go used in the admin sdk.

Steps to reproduce:

Failed to build and run the project for sending push notifications.

  1. Add the main.go file in the project.
  2. run the commands: go mod init, go mod tidy, go mod vendor

Relevant Code:

tried with go version: 1.14, 1.17

main.go

package main

import (
    "context"
    "firebase.google.com/go/messaging"
    "fmt"
    "github.com/firebase/firebase-admin-go"
    "log"
)

func main() {
    ctx := context.Background()
    app, err := firebase.NewApp(context.Background(), nil, nil)
    if err != nil {
        log.Fatalf("error initializing app: %v\n", err)
    }
    client, err := app.Messaging(ctx)
    if err != nil {
        log.Fatalf("error getting Messaging client: %v\n", err)
    }
        registrationTokens := []string{
            "YOUR_REGISTRATION_TOKEN_1",
            "YOUR_REGISTRATION_TOKEN_n",
        }
        message := &messaging.MulticastMessage{
            Data: map[string]string{
                "score": "850",
                "time":  "2:45",
            },
            Tokens: registrationTokens,
        }
        br, err := client.SendMulticast(context.Background(), message)
        if err != nil {
            log.Fatalln(err)
        }
        fmt.Printf("%d messages were sent successfully\n", br.SuccessCount)

}
lahirumaramba commented 2 years ago

Hi @hiteshkumar848 Could you try changing your imports to the following instead:

    firebase "firebase.google.com/go/v4"
    "firebase.google.com/go/v4/messaging"

You can also refer to https://github.com/firebase/firebase-admin-go/blob/master/snippets/messaging.go for sample code.