Code Monkey home page Code Monkey logo

golang-twitch's Introduction

golang-twitch

Twitch API PubSub interface and automatically take care of API limits. Also it will handle automatically reconnections, ping/pong and maintenance requests. Designed by PubSub guide: https://dev.twitch.tv/docs/pubsub/

ps := pubsub.New()

ps.OnConnect(func(c *pubsub.Connection) {
    log.Printf("OnConnect (ID: %d)\n", c.ID)
})

ps.OnDisconnect(func(c *pubsub.Connection) {
    log.Printf("OnDisconnect (ID: %d)\n", c.ID)
})

ps.OnError(func(c *pubsub.Connection, err error) {
    log.Printf("OnError (ID: %d), err: %s\n", c.ID, err)
})

ps.OnInfo(func(c *pubsub.Connection, str string) {
    log.Printf("OnInfo (ID: %d), str: %s\n", c.ID, str)
})

ps.OnMessage(func(c *pubsub.Connection, msg *pubsub.Answer) {
    log.Printf("OnMessage (ID: %d), msg: %#v\n", c.ID, msg)
})

ps.OnPing(func(c *pubsub.Connection, start time.Time) {
    log.Printf("OnPing (ID: %d), start: %d\n", c.ID, start.Unix())
})

ps.OnPong(func(c *pubsub.Connection, start, end time.Time) {
    log.Printf("OnPong (ID: %d), start: %d, end: %d\n", c.ID, start.Unix(), end.Unix())
})

ps.Listen(context.Background(), "community-points-channel-v1", "<UserID>")

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
<-interrupt

ps.Close()

Full example here: https://github.com/vladimirok5959/golang-twitch/blob/main/cmd/cli/main.go

golang-twitch's People

Contributors

vladimirok5959 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.