Skip to content
Permalink
0612daeed6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
115 lines (77 sloc) 2.08 KB
// Query the google API for log information.
// Created by Marcus Barone.
// Note: this was only made to practice golang
// and to better understand the logging process
package main
import (
"bufio"
"fmt"
"os"
"strings"
"strconv"
"io/ioutil"
"log"
"net/http"
)
func main() {
fmt.Println("Query ct.googleapis.com/pilot/ct/v1 for logs.")
fmt.Println("To get the signed tree head, type 'sth'")
fmt.Println("To get entries, type 'entries'")
fmt.Println("To quit, use ctrl+c or type 'quit'")
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
var text string
text = strings.ToLower(input.Text())
if text == "sth" {
resp, err := http.Get("https://ct.googleapis.com/pilot/ct/v1/get-sth")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
} else if text == "entries" {
fmt.Println("Enter start:")
input.Scan()
var start int
_, start_err := fmt.Sscan(input.Text(), &start)
if start_err != nil {
fmt.Println(start_err)
goto loop
}
fmt.Println("Enter end:")
input.Scan()
var end int
_, end_err := fmt.Sscan(input.Text(), &end)
if end_err != nil {
fmt.Println(end_err)
goto loop
}
if start > end {
fmt.Println("Start must be smaller than end.")
goto loop
}
resp, err := http.Get("https://ct.googleapis.com/pilot/ct/v1/get-entries?start=" + strconv.Itoa(start) + "&end=" + strconv.Itoa(end))
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
} else if text == "quit" {
break
} else {
fmt.Println("Invalid input");
}
loop:
fmt.Println("\nTo get the signed tree head, type 'sth'")
fmt.Println("To get entries, type 'entries'")
fmt.Println("To quit, use ctrl+c or type 'quit'")
}
}