docs: add docstrings

This commit is contained in:
James Houlahan
2020-08-12 15:46:19 +02:00
parent 3101fc5543
commit 9f24c666b9
4 changed files with 7 additions and 4 deletions

View File

@ -47,6 +47,7 @@ import (
"github.com/ProtonMail/proton-bridge/internal/api" "github.com/ProtonMail/proton-bridge/internal/api"
"github.com/ProtonMail/proton-bridge/internal/bridge" "github.com/ProtonMail/proton-bridge/internal/bridge"
"github.com/ProtonMail/proton-bridge/internal/cookies"
"github.com/ProtonMail/proton-bridge/internal/events" "github.com/ProtonMail/proton-bridge/internal/events"
"github.com/ProtonMail/proton-bridge/internal/frontend" "github.com/ProtonMail/proton-bridge/internal/frontend"
"github.com/ProtonMail/proton-bridge/internal/imap" "github.com/ProtonMail/proton-bridge/internal/imap"
@ -56,7 +57,6 @@ import (
"github.com/ProtonMail/proton-bridge/pkg/args" "github.com/ProtonMail/proton-bridge/pkg/args"
"github.com/ProtonMail/proton-bridge/pkg/config" "github.com/ProtonMail/proton-bridge/pkg/config"
"github.com/ProtonMail/proton-bridge/pkg/constants" "github.com/ProtonMail/proton-bridge/pkg/constants"
"github.com/ProtonMail/proton-bridge/pkg/cookies"
"github.com/ProtonMail/proton-bridge/pkg/listener" "github.com/ProtonMail/proton-bridge/pkg/listener"
"github.com/ProtonMail/proton-bridge/pkg/pmapi" "github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/ProtonMail/proton-bridge/pkg/updates" "github.com/ProtonMail/proton-bridge/pkg/updates"
@ -275,7 +275,7 @@ func run(context *cli.Context) (contextError error) { // nolint[funlen]
cm.SetRoundTripper(cfg.GetRoundTripper(cm, eventListener)) cm.SetRoundTripper(cfg.GetRoundTripper(cm, eventListener))
// Cookies must be persisted across restarts. // Cookies must be persisted across restarts.
jar, err := cookies.New(cookies.NewPersister(pref)) jar, err := cookies.NewCookieJar(cookies.NewPersister(pref))
if err != nil { if err != nil {
logrus.WithError(err).Warn("Could not create cookie jar") logrus.WithError(err).Warn("Could not create cookie jar")
} else { } else {

View File

@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>. // along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Package cookies implements a persistent cookie jar which satisfies the http.CookieJar interface.
package cookies package cookies
import ( import (
@ -26,13 +27,15 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// Jar implements http.CookieJar by wrapping the standard library's cookiejar.Jar.
// The jar uses a Persister to load cookies at startup and save cookies when set.
type Jar struct { type Jar struct {
jar *cookiejar.Jar jar *cookiejar.Jar
persister *Persister persister *Persister
locker sync.Locker locker sync.Locker
} }
func New(persister *Persister) (*Jar, error) { func NewCookieJar(persister *Persister) (*Jar, error) {
jar, err := cookiejar.New(nil) jar, err := cookiejar.New(nil)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -36,7 +36,7 @@ func TestJar(t *testing.T) {
ts := getTestServer(t, testCookies...) ts := getTestServer(t, testCookies...)
defer ts.Close() defer ts.Close()
jar, err := New(NewPersister(make(testPersister))) jar, err := NewCookieJar(NewPersister(make(testPersister)))
require.NoError(t, err) require.NoError(t, err)
client := &http.Client{Jar: jar} client := &http.Client{Jar: jar}