Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofmt #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const (

// for multi.Info_read()
const (
CURLMSG_NONE = C.CURLMSG_NONE
CURLMSG_DONE = C.CURLMSG_DONE
CURLMSG_LAST = C.CURLMSG_LAST
CURLMSG_NONE = C.CURLMSG_NONE
CURLMSG_DONE = C.CURLMSG_DONE
CURLMSG_LAST = C.CURLMSG_LAST
)
919 changes: 460 additions & 459 deletions const_gen.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions easy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ import (
"fmt"
"mime"
"path"
"unsafe"
"sync"
"unsafe"
)

type CurlInfo C.CURLINFO
Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *contextMap) Delete(k uintptr) {
delete(c.items, k)
}

var context_map = &contextMap {
var context_map = &contextMap{
items: make(map[uintptr]*CURL),
}

Expand Down
2 changes: 1 addition & 1 deletion easy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"sync"
"testing"
)

func setupTestServer(serverContent string) *httptest.Server {
Expand Down
48 changes: 24 additions & 24 deletions logging.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package curl

import (
"log"
"log"
)

const (
_DEBUG = 10 * (iota + 1)
_INFO
_WARN
_ERROR
_DEBUG = 10 * (iota + 1)
_INFO
_WARN
_ERROR
)

const _DEFAULT_LOG_LEVEL = _WARN
Expand All @@ -19,38 +19,38 @@ var log_level = _DEFAULT_LOG_LEVEL
// messages that are logged. Available log levels are: "DEBUG", "INFO",
// "WARN", "ERROR" and "DEFAULT_LOG_LEVEL".
func SetLogLevel(levelName string) {
switch levelName {
case "DEBUG":
log_level = _DEBUG
case "INFO":
log_level = _INFO
case "WARN":
log_level = _WARN
case "ERROR":
log_level = _ERROR
case "DEFAULT_LOG_LEVEL":
log_level = _DEFAULT_LOG_LEVEL
}
switch levelName {
case "DEBUG":
log_level = _DEBUG
case "INFO":
log_level = _INFO
case "WARN":
log_level = _WARN
case "ERROR":
log_level = _ERROR
case "DEFAULT_LOG_LEVEL":
log_level = _DEFAULT_LOG_LEVEL
}
}

func logf(limitLevel int, format string, args ...interface{}) {
if log_level <= limitLevel {
log.Printf(format, args...)
}
if log_level <= limitLevel {
log.Printf(format, args...)
}
}

func debugf(format string, args ...interface{}) {
logf(_DEBUG, format, args...)
logf(_DEBUG, format, args...)
}

func infof(format string, args ...interface{}) {
logf(_INFO, format, args...)
logf(_INFO, format, args...)
}

func warnf(format string, args ...interface{}) {
logf(_WARN, format, args...)
logf(_WARN, format, args...)
}

func errorf(format string, args ...interface{}) {
logf(_ERROR, format, args...)
logf(_ERROR, format, args...)
}
86 changes: 47 additions & 39 deletions logging_test.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,72 @@

package curl

import (
"testing"
"bytes"
"fmt"
"log"
"os"
"fmt"
"regexp"
"testing"
)

func TestDefaultLogLevel(t *testing.T) {
if log_level != _DEFAULT_LOG_LEVEL {t.Error("Test failed, expected DEFAULT_LOG_LEVEL level.")}
if log_level != _DEFAULT_LOG_LEVEL {
t.Error("Test failed, expected DEFAULT_LOG_LEVEL level.")
}
}

func TestSetLogLevel(t *testing.T) {
SetLogLevel("DEBUG")
defer SetLogLevel("DEFAULT_LOG_LEVEL")
if log_level != _DEBUG {t.Error("Test failed, expected DEBUG level.")}
SetLogLevel("INFO")
if log_level != _INFO {t.Error("Test failed, expected INFO level.")}
SetLogLevel("WARN")
if log_level != _WARN {t.Error("Test failed, expected WARN level.")}
SetLogLevel("ERROR")
if log_level != _ERROR {t.Error("Test failed, expected ERROR level.")}
SetLogLevel("DEBUG")
defer SetLogLevel("DEFAULT_LOG_LEVEL")
if log_level != _DEBUG {
t.Error("Test failed, expected DEBUG level.")
}
SetLogLevel("INFO")
if log_level != _INFO {
t.Error("Test failed, expected INFO level.")
}
SetLogLevel("WARN")
if log_level != _WARN {
t.Error("Test failed, expected WARN level.")
}
SetLogLevel("ERROR")
if log_level != _ERROR {
t.Error("Test failed, expected ERROR level.")
}
}

var (
testFormat = "test format %s"
testArgument = "test string 1"
expectedRegexp = regexp.MustCompile(".*" + fmt.Sprintf(testFormat, testArgument) + "\n$")
testFormat = "test format %s"
testArgument = "test string 1"
expectedRegexp = regexp.MustCompile(".*" + fmt.Sprintf(testFormat, testArgument) + "\n$")
)


func TestLogf(t *testing.T) {
buf := new(bytes.Buffer)
log.SetOutput(buf)
defer log.SetOutput(os.Stderr)
SetLogLevel("DEBUG")
defer SetLogLevel("DEFAULT_LOG_LEVEL")
buf := new(bytes.Buffer)
log.SetOutput(buf)
defer log.SetOutput(os.Stderr)
SetLogLevel("DEBUG")
defer SetLogLevel("DEFAULT_LOG_LEVEL")

logf(_DEBUG, testFormat, testArgument)
line := buf.String()
matched := expectedRegexp.MatchString(line)
if !matched {
t.Errorf("log output should match %q and is %q.", expectedRegexp, line)
}
logf(_DEBUG, testFormat, testArgument)
line := buf.String()
matched := expectedRegexp.MatchString(line)
if !matched {
t.Errorf("log output should match %q and is %q.", expectedRegexp, line)
}
}

func TestLogfUsesLogLevel(t *testing.T) {
buf := new(bytes.Buffer)
log.SetOutput(buf)
defer log.SetOutput(os.Stderr)
SetLogLevel("WARN")
defer SetLogLevel("DEFAULT_LOG_LEVEL")
buf := new(bytes.Buffer)
log.SetOutput(buf)
defer log.SetOutput(os.Stderr)
SetLogLevel("WARN")
defer SetLogLevel("DEFAULT_LOG_LEVEL")

logf(_DEBUG, testFormat, testArgument)
line := buf.String()
expectedLine := ""
if line != expectedLine {
t.Errorf("log output should match %q and is %q.", expectedLine, line)
}
logf(_DEBUG, testFormat, testArgument)
line := buf.String()
expectedLine := ""
if line != expectedLine {
t.Errorf("log output should match %q and is %q.", expectedLine, line)
}
}
23 changes: 12 additions & 11 deletions multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ static CURLMcode curl_multi_fdset_pointer(CURLM *handle,
int *max_fd)
{
return curl_multi_fdset(handle, read_fd_set, write_fd_set, exc_fd_set, max_fd);
}
}
static CURLMsg *curl_multi_info_read_pointer(CURLM *handle, int *msgs_in_queue)
{
return curl_multi_info_read(handle, msgs_in_queue);
}
}
*/
import "C"

import (
"unsafe"
"syscall"
"syscall"
"unsafe"
)

type CurlMultiError C.CURLMcode
type CurlMultiMsg C.CURLMSG
type CurlMultiMsg C.CURLMSG

func (e CurlMultiError) Error() string {
// ret is const char*, no need to free
Expand All @@ -52,26 +52,27 @@ func newCurlMultiError(errno C.CURLMcode) error {
return CurlMultiError(errno)
}

func newCURLMessage(message *C.CURLMsg) (msg *CURLMessage){
func newCURLMessage(message *C.CURLMsg) (msg *CURLMessage) {
if message == nil {
return nil
}
msg = new(CURLMessage)
msg.Msg = CurlMultiMsg(message.msg)
msg.Easy_handle = &CURL{handle: message.easy_handle}
msg.Data = message.data
return msg
return msg
}

type CURLM struct {
handle unsafe.Pointer
}

var dummy unsafe.Pointer

type CURLMessage struct {
Msg CurlMultiMsg
Msg CurlMultiMsg
Easy_handle *CURL
Data [unsafe.Sizeof(dummy)]byte
Data [unsafe.Sizeof(dummy)]byte
}

// curl_multi_init - create a multi handle
Expand Down Expand Up @@ -149,12 +150,12 @@ func (mcurl *CURLM) Fdset(rset, wset, eset *syscall.FdSet) (int, error) {
exc := unsafe.Pointer(eset)
maxfd := C.int(-1)
err := newCurlMultiError(C.curl_multi_fdset_pointer(p, read, write,
exc, &maxfd))
exc, &maxfd))
return int(maxfd), err
}

func (mcurl *CURLM) Info_read() (*CURLMessage, int) {
p := mcurl.handle
left := C.int(0)
return newCURLMessage(C.curl_multi_info_read_pointer(p, &left)), int(left)
return newCURLMessage(C.curl_multi_info_read_pointer(p, &left)), int(left)
}