cookiestxt

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 7 Imported by: 1

README

cookiestxt

Build Status Go Reference GoReportCard Coverage Status Mentioned in Awesome Go

cookiestxt implement parser of cookies txt format

Usage

package main

import (
        "log"
        "strings"

        "github.com/mengzhuo/cookiestxt"
)

func main() {
        buf := strings.NewReader(`
        # This example taken from http://www.cookiecentral.com/faq/#3.5
        #HttpOnly_.netscape.com TRUE / FALSE 946684799 NETSCAPE_ID 100103
        `)
        cl, err := cookiestxt.Parse(buf)
        log.Print(cl, err)
}
$ go run main.go 

[NETSCAPE_ID=100103; Path=/; Domain=netscape.com; Expires=Fri, 31 Dec 1999 23:59:59
 GMT; HttpOnly] <nil>

Documentation

Overview

Package cookiestxt implement parser of cookies txt format that commonly supported by curl / wget / aria2c / chrome / firefox

see http://www.cookiecentral.com/faq/#3.5 for more detail

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(rd io.Reader) (cl []*http.Cookie, err error)

Parse cookie txt file format from input stream

Example
buf := strings.NewReader(`
        # This example taken from http://www.cookiecentral.com/faq/#3.5
        #HttpOnly_.netscape.com TRUE / FALSE 946684799 NETSCAPE_ID 100105
        `)
cl, _ := Parse(buf)
fmt.Printf("Name[0]=%s, Value[0]=%s, Len=%d", cl[0].Name, cl[0].Value, len(cl))
Output:

Name[0]=NETSCAPE_ID, Value[0]=100105, Len=1

func ParseLine

func ParseLine(raw string) (c *http.Cookie, err error)

ParseLine parse single cookie from one line

Example
c, _ := ParseLine(".netscape.com TRUE / TRUE 946684799 NETSCAPE_ID 100105")
fmt.Printf("Name=%s, Value=%s\n", c.Name, c.Value)
Output:

Name=NETSCAPE_ID, Value=100105

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL