// The github-api and the oauth api for golang was used for this program.// The first part is to check if there are notifications from github, // the second part is to send the signal if there are.packagemainimport("bytes""encoding/json""fmt""log""net/http""time""golang.org/x/net/context""github.com/google/go-github/github""golang.org/x/oauth2")typesignalstruct{IDint64`json:"id"`// Not used when creating a signalPidstring`json:"pid"`// DK5QPIDZoneIDstring`json:"zoneId"`// KEY_A, KEY_B, etc...Namestring`json:"name"`// message titleMessagestring`json:"message"`// message bodyEffectstring`json:"effect"`// e.g. SET_COLOR, BLINK, etc...Colorstring`json:"color"`// color in hex format. E.g.: "#FF0044"}funccheckErr(errerror){iferr!=nil{log.Fatal(err)}}/**
* this function is used to get Authentification using a oauth token
*/funcgetAuth()*github.Client{ctx:=context.Background()// put your own OAuth Tokents:=oauth2.StaticTokenSource(&oauth2.Token{AccessToken:"PUT_YOUR_OWN_OAUTH_TOKEN"})tc:=oauth2.NewClient(ctx,ts)client:=github.NewClient(tc)returnclient}funcgetNotif(client*github.Client)[]*github.Notification{ctx:=context.Background()notifs,_,err:=client.GetActivity().ListNotifications(ctx,nil)checkErr(err)returnnotifs}/**
* this function is used to know if there are notifications
*/funcisNotification(client*github.Client)bool{isNotif:=falsenotifs:=getNotif(client)iflen(notifs)>0{isNotif=true}returnisNotif}funcsendSignal(){port:="27301"// Q desktop public API port #.// Signal to be sent: A key set to blue coloroneSignal:=signal{0,"DK5QPID","KEY_A","Hello oneSignal","Notification on your github","SET_COLOR","#00F",true}// Encode to JSONsignalJSON:=new(bytes.Buffer)json.NewEncoder(signalJSON).Encode(&oneSignal)// Construct API URLurl:="http://localhost:"+port+"/api/1.0/signals"// Make HTTP POST call._,err:=http.Post(url,"application/json; charset=utf-8",signalJSON)checkErr(err)fmt.Println("Sending signal to the keyboard")}funcmain(){// first we get authentificationclient:=getAuth()// this is to make sure that the signal is sent only when there are new notificationsisSignalSent:=falsefortrue{// then we check if there is a notification// if there are notifications and the signal was not send, we send the signalifisNotif:=isNotification(client);isNotif&&!isSignalSent{sendSignal()isSignalSent=true// if there is no notifications, we reset the flag that tells if the signal was sent or not// to make sure that a signal will be sent when there are new notifications}elseif!isNotif&&isSignalSent{isSignalSent=false}// we wait 2 seconds before doing this process againtime.Sleep(time.Duration(2)*time.Second)}}