I want to send a system notifications to windows using golang.
How can this be done?
if you awnser contains a cross platform solution it would be even better.
Finding system notification with Golang in 2020 and found this: https://github.com/gen2brain/beeep . It looks like currently still actively maintained.
Example from repo:
err := beeep.Notify("Title", "Message body", "assets/information.png")
if err != nil {
panic(err)
}
Even it works great, actually I feel that this app was made mainly for producing "beep" sound on the computer speaker. Based on the app name which is "beeep" :). You can check on example page if interest in makes those "beep" sound too.
I'm assuming you are looking for desktop notifications. There are a few different libraries that can do this for you. Originally I found this with a simple Google search
Link / Dependency URL: github.com/0xAX/notificator
Here is the example on their README.md page:
package main
import (
"github.com/0xAX/notificator"
)
var notify *notificator.Notificator
func main() {
notify = notificator.New(notificator.Options{
DefaultIcon: "icon/default.png",
AppName: "My test App",
})
notify.Push("title", "text", "/home/user/icon.png", notificator.UR_CRITICAL)
}
Related
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)
I used to set up a Fabric network and deployed a fabric network and basic application using a Fabric and Fabric GoLang SDK. I'm able to do the query and write to the chain.
Is there any way to retrieve the Block Info? Like block height and current hash?
+ I'm unable to find out a documentation for GoLang Fabric SDK.
I followed following code and tutorial,
Fabric Basic App - Tutorial
https://chainhero.io/2017/07/tutorial-build-blockchain-app/
Fabric Basic App using GoLang SDK - Code
https://github.com/chainHero/heroes-service/
GoLang SDK - Official SDK
https://github.com/hyperledger/fabric-sdk-go
In general, the sdk will provide the basic method such you said GetBlockInfo,I have search for the GoLang SDK, it can not be found. While Java sdk provide this such method reference this java test .
Another way to use these method(you must know a little fabric source code), in fact these method are included in the system chaincode, you could invoke the system chancode just like you invoke the normal chaincode.
A example is following:
from the go sdk test ,you could see this,
response, err := chClient.Query(chclient.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
just change the params
response, err := chClient.Query(chclient.Request{ChaincodeID: "qscc", Fcn: "invoke", Args: integration.ExampleCCQueryArgs("GetChainInfo")})
qscc is a system chancode,you could download the fabric source code,and from qscc file,you could see(it provide many invoke service):
GetChainInfo string = "GetChainInfo"
GetBlockByNumber string = "GetBlockByNumber"
GetBlockByHash string = "GetBlockByHash"
GetTransactionByID string = "GetTransactionByID"
GetBlockByTxID string = "GetBlockByTxID"
Go sdk(fabric-sdk-go/pkg/client/ledger) provides several methods for getting information about blockchain. For example:
...
client, err := ledger.New(channelContext)
block, err := client.QueryBlockByHash(blockHash)
block, err = client.QueryBlock(blockNumber)
The Go SDK now includes methods for querying block information. These methods are contained within the ledger client package.
You can see an example in the ledger client integration test.
I'm adding Push Notifications to my Mac app. The notifications are showing up just fine, but for some reason I can't get the sound effects to play the way I would think they should.
I'm passing in a custom sound to play, "custom.caf" in the apns payload. This works currently for our iOS app. It doesn't play anything when passed into the Mac app. Digging around in the very limited Apple documentation, the PushyMac app shows that you have to play the sound manually based on the userInfo dictionary that comes in for the push. If I play the sound manually while the app is running, I get the sound effect to play.
My problem is when the app is closed and not running. I still get push notifications as expected, but no sounds play. From what I can tell, I'm just screwed. I have other Mac apps that still manage to play sounds when they aren't running. Specifically my email app, Spark. So I know it is possible, but I can't figure out what the secret sauce is to pull it off. Please help!!
It's quite simple to implement the custom sound capability for Apple Push Notifications; the problem is that the documentation does not mention what is required to do this.
The critical component that is required is an extension — (eg. using the Today Extension). Creating a new target in your project including the extension, your custom sound(s), and the standard APN functions are all that's required. The key to getting the custom sounds working though while your application isn't running is simply having the extension (and it's included NotificationCenter.framework) present in your application.
Add New Target > Today Extension:
Today Extension > Build Phases > Copy Bundle Resources > Custom Sound:
The only specific APN functions that need to be in your main application are the following:
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSApplication.shared().
registerForRemoteNotifications(matching:
[.alert, .sound, .badge])
NSApp.dockTile.badgeLabel = nil
}
func application(_ application: NSApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
}
func application(_ application: NSApplication, didReceiveRemoteNotification
userInfo: [String : Any]) {
}
func application(_ application: NSApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("could not register for notfications: \(error)")
}
If you are getting two sounds playing at the same time it's likely that you've got code that is calling AudioServicesPlaySystemSound and can be removed as the NotificationCenter.framework seems to handle all that without adding anything additional.