{"id":18765028,"url":"https://github.com/moonrhythm/session","last_synced_at":"2025-04-13T05:10:41.622Z","repository":{"id":57480562,"uuid":"88483725","full_name":"moonrhythm/session","owner":"moonrhythm","description":"Session Manager and Middleware for Go net/http","archived":false,"fork":false,"pushed_at":"2025-02-11T15:13:13.000Z","size":218,"stargazers_count":11,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T22:02:14.183Z","etag":null,"topics":["golang","http","middleware","session","session-management"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moonrhythm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-04-17T07:34:05.000Z","updated_at":"2025-02-11T15:12:43.000Z","dependencies_parsed_at":"2023-07-13T21:44:55.473Z","dependency_job_id":null,"html_url":"https://github.com/moonrhythm/session","commit_stats":null,"previous_names":["acoshift/session"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonrhythm%2Fsession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonrhythm%2Fsession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonrhythm%2Fsession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonrhythm%2Fsession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moonrhythm","download_url":"https://codeload.github.com/moonrhythm/session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665747,"owners_count":21142123,"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","http","middleware","session","session-management"],"created_at":"2024-11-07T18:32:29.287Z","updated_at":"2025-04-13T05:10:41.600Z","avatar_url":"https://github.com/moonrhythm.png","language":"Go","readme":"# session\n\n[![codecov](https://codecov.io/gh/moonrhythm/session/branch/master/graph/badge.svg)](https://codecov.io/gh/moonrhythm/session)\n[![Go Report Card](https://goreportcard.com/badge/github.com/moonrhythm/session)](https://goreportcard.com/report/github.com/moonrhythm/session)\n[![GoDoc](https://godoc.org/github.com/moonrhythm/session?status.svg)](https://godoc.org/github.com/moonrhythm/session)\n\nSession Middleware for Golang\n\n## Example with Middleware\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"net/http\"\n    \"time\"\n\n    \"github.com/moonrhythm/session\"\n    \"github.com/moonrhythm/session/store\"\n)\n\nfunc main() {\n    mux := http.NewServeMux()\n    mux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n        if r.URL.Path != \"/\" {\n            http.NotFound(w, r)\n            return\n        }\n\n        s, _ := session.Get(r.Context(), \"sess\")\n        cnt := s.GetInt(\"counter\")\n        cnt++\n        s.Set(\"counter\", cnt)\n        w.Header().Set(\"Content-Type\", \"text/html\")\n        fmt.Fprintf(w, \"Couter: %d\u003cbr\u003e\u003ca href=\\\"/reset\\\"\u003eReset\u003c/a\u003e\", cnt)\n    })\n    mux.HandleFunc(\"/reset\", func(w http.ResponseWriter, r *http.Request) {\n        s, _ := session.Get(r.Context(), \"sess\")\n        s.Del(\"counter\")\n        http.Redirect(w, r, \"/\", http.StatusFound)\n    })\n\n    h := session.Middleware(session.Config{\n        Domain:   \"localhost\",\n        HTTPOnly: true,\n        Secret:   []byte(\"testsecret1234\"),\n        MaxAge:   time.Minute,\n        Path:     \"/\",\n        Secure:   session.PreferSecure,\n        Store:    new(store.Memory),\n    })(mux)\n    // equals to\n    // h := session.New(session.Config{...}).Middleware()(mux)\n\n    log.Fatal(http.ListenAndServe(\":8080\", h))\n}\n\n```\n\n## Example with Manager\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"net/http\"\n    \"time\"\n\n    \"github.com/moonrhythm/session\"\n    \"github.com/moonrhythm/session/store\"\n)\n\nfunc main() {\n    mux := http.NewServeMux()\n\n    m := session.New(session.Config{\n        Domain:   \"localhost\",\n        HTTPOnly: true,\n        Secret:   []byte(\"testsecret1234\"),\n        MaxAge:   time.Minute,\n        Path:     \"/\",\n        Secure:   session.PreferSecure,\n        Store:    new(store.Memory),\n    })\n\n    mux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n        if r.URL.Path != \"/\" {\n            http.NotFound(w, r)\n            return\n        }\n\n        s, _ := m.Get(r, \"sess\")\n        cnt := s.GetInt(\"counter\")\n        cnt++\n        s.Set(\"counter\", cnt)\n        m.Save(r.Context(), w, s)\n        w.Header().Set(\"Content-Type\", \"text/html\")\n        fmt.Fprintf(w, \"Couter: %d\u003cbr\u003e\u003ca href=\\\"/reset\\\"\u003eReset\u003c/a\u003e\", cnt)\n    })\n    mux.HandleFunc(\"/reset\", func(w http.ResponseWriter, r *http.Request) {\n        s, _ := m.Get(r, \"sess\")\n        s.Del(\"counter\")\n        m.Save(r.Context(), w, s)\n        http.Redirect(w, r, \"/\", http.StatusFound)\n    })\n\n    log.Fatal(http.ListenAndServe(\":8080\", mux))\n}\n```\n\n[See more examples](https://github.com/moonrhythm/session/tree/master/example)\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonrhythm%2Fsession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoonrhythm%2Fsession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonrhythm%2Fsession/lists"}