{"id":21525250,"url":"https://github.com/anikhasibul/push","last_synced_at":"2025-10-17T04:01:23.658Z","repository":{"id":144241998,"uuid":"163444418","full_name":"AnikHasibul/push","owner":"AnikHasibul","description":"package push gives you the ability to use push and pull mechanism for notification or message via websocket or even http client.","archived":false,"fork":false,"pushed_at":"2019-03-08T20:44:18.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T05:25:11.821Z","etag":null,"topics":["golang","notification-center","pub-sub","push-pull","websockets"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnikHasibul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-28T19:48:44.000Z","updated_at":"2019-01-28T10:24:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"ee0ea63a-65ae-4a12-92a2-5f55fd12703c","html_url":"https://github.com/AnikHasibul/push","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnikHasibul%2Fpush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnikHasibul%2Fpush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnikHasibul%2Fpush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnikHasibul%2Fpush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnikHasibul","download_url":"https://codeload.github.com/AnikHasibul/push/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085008,"owners_count":20395523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","notification-center","pub-sub","push-pull","websockets"],"created_at":"2024-11-24T01:34:02.024Z","updated_at":"2025-10-17T04:01:18.623Z","avatar_url":"https://github.com/AnikHasibul.png","language":"Go","readme":"# push\n--\n    import \"github.com/anikhasibul/push\"\n\nPackage push gives you the ability to use push and pull mechanism for\nnotification or message via websocket or even http client.\n\n## Usage\n\n#### func  DeleteSession\n\n```go\nfunc DeleteSession(sessionID interface{})\n```\nDeleteSession deletes the given session from memory. It's safe to delete a\nnon-existent session.\n\n#### func  Exists\n\n```go\nfunc Exists(sessionID interface{}) bool\n```\nExists returns true if the given session exists.\n\n#### type Client\n\n```go\ntype Client struct {\n}\n```\n\nClient holds the methods for a perticular client.\n\n#### func (*Client) Close\n\n```go\nfunc (c *Client) Close()\n```\nClose closes a client channel/connection\n\n#### func (*Client) DeleteSelf\n\n```go\nfunc (c *Client) DeleteSelf()\n```\nDeleteSelf deletes the current client from the current session.\n\n#### func (*Client) Key\n\n```go\nfunc (c *Client) Key() interface{}\n```\nKey returns the current clientID/name/key.\n\n#### func (*Client) KeyString\n\n```go\nfunc (c *Client) KeyString() string\n```\nKeyString returns the current clientID/name/key in string type.\n\n#### func (*Client) Pull\n\n```go\nfunc (c *Client) Pull() (content interface{}, err error)\n```\nPull pulls a message for the current client.\n\n    var (\n    \tuserID := 123446555\n    \tclID := \"device_mobile_5445\"\n    )\n\n    s := NewSession(userID)\n    c := s.NewClient(clID)\n    defer c.DeleteSelf()\n\n    msg, err := c.Pull()\n    if err != nil {\n    \tpanic(err)\n    }\n    fmt.Println(msg)\n\n#### func (*Client) PullChan\n\n```go\nfunc (c *Client) PullChan() (ClientChan, error)\n```\nPullChan returns a channel for receiving messages for the current client.\n\n    var (\n    \tuserID := 123446555\n    \tclID := \"device_mobile_5645\"\n    )\n\n    s := NewSession(userID)\n    c := s.NewClient(clID)\n    defer c.DeleteSelf()\n\n    ch, err := c.PullChan()\n    if err != nil {\n    \tpanic(err)\n    }\n\n    msg := \u003c-ch\n    fmt.Println(msg)\n\nExclusively usable with websockets\n\n#### type ClientChan\n\n```go\ntype ClientChan chan interface{}\n```\n\nClientChan holds a chan of interface type to provide type flexibility on pushed\nmessage\n\n#### type Session\n\n```go\ntype Session struct {\n\n\t//\t`MaxChannelBuffer` means the maximum buffered message on a client channel. `make(chan interface{},MaxChannelBuffer)`.\n\t// Default value is 10\n\tMaxChannelBuffer int\n}\n```\n\nSession holds the methods for push and pull mechanism\n\n#### func  NewSession\n\n```go\nfunc NewSession(sessionID interface{}) *Session\n```\nNewSession returns a client session.\n\nA single user (sessionID) can use multiple devices (clientID). That's why the\nclientID should be unique for each device/client/connection.\n\n    `sessionID` means the userID or a groupID. Once a `Session` receives a message, it pushes the message to all registered client for this session.\n\n#### func (*Session) Clients\n\n```go\nfunc (s *Session) Clients() []interface{}\n```\nClients returns the keys/IDs/names of active clients on current session.\n\n#### func (*Session) DeleteClient\n\n```go\nfunc (s *Session) DeleteClient(clientID interface{})\n```\nDeleteClient deletes the given client from the current session. It's safe to\ndelete a non-existent client.\n\n#### func (*Session) DeleteSelf\n\n```go\nfunc (s *Session) DeleteSelf()\n```\nDeleteSelf deletes the current session from memory.\n\n#### func (*Session) Exists\n\n```go\nfunc (s *Session) Exists(clientID interface{}) bool\n```\nExists returns true if the given client exists.\n\n#### func (*Session) Len\n\n```go\nfunc (s *Session) Len() int\n```\nLen returns the length/count of active clients on current session.\n\n#### func (*Session) NewClient\n\n```go\nfunc (s *Session) NewClient(clientID interface{}) *Client\n```\nNewClient returns a `Client`.\n\nIt creates a new client if the given `clientID` does not exist.\n\nIt returns the existing client for the given `clientID` if it already exists.\n\nit panics if the given `clientID` is nil.\n\nA single user (sessionID) can use multiple devices (clientID). That's why the\nclientID should be unique for each device/client/connection.\n\n#### func (*Session) Push\n\n```go\nfunc (s *Session) Push(message interface{})\n```\nPush sends a message to all connected clients on the given session.\n\n    s := push.NewClient(userID, nil,0)\n    s.Push(\"Hello world!\")\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanikhasibul%2Fpush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanikhasibul%2Fpush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanikhasibul%2Fpush/lists"}