Skip to content

Instantly share code, notes, and snippets.

View deankarn's full-sized avatar
Coffee In -> Code Out

Dean Karn deankarn

Coffee In -> Code Out
  • Hubspot
  • /dev/tty0
View GitHub Profile
@deankarn
deankarn / response_writer.go
Created April 30, 2015 15:50
Wrapping/implementing golang's http.ResponseWriter example
// LogResponseWritter wraps the standard http.ResponseWritter allowing for more
// verbose logging
type LogResponseWritter struct {
status int
size int
http.ResponseWriter
}
// func NewMyResponseWriter(res http.ResponseWriter) *MyResponseWriter {
// // Default the status code to 200
// config
c, err := mylib.New(&mylib.Config{
Username: "uname",
Password: "pw",
})
// methods
c, err := mylib.New("required")
if err !=nil{
// ...
package mylib
import "net/http"
// New create a new Instance of mylib
func New(someAlwaysRequiredValue string) (*Builder, error) {
return &Builder{
// some nice sane defaults if necessary
}, nil
}
package mylib
import "net/http"
// New create a new Instance of mylib
func New(someAlwaysRequiredValue string, options ...func(*Instance) error) (*Instance, error) {
return &Instance{
client: new(http.Client), // default no auth client
}, nil
}
package mylib
import "net/http"
// New create a new Instance of mylib
func New(someAlwaysRequiredValue string) (*Instance, error) {
return &Instance{
client: new(http.Client), // default no auth client
}, nil
}
package mylib
import "net/http"
// Config contains all library configuration data
type Config struct {
Username string
Password string
}
@deankarn
deankarn / do-things-library-tests.go
Created July 12, 2018 16:10
tests for the do things Library
package lib
import (
"testing"
"os"
"github.com/stretchr/testify/require"
)
@deankarn
deankarn / do-things-library-example.go
Created July 12, 2018 16:04
Do Things Library Example
package lib
import (
"errors"
"strings"
)
// DoThings ...
func DoThings(s string) error {
if strings.Contains(s, "thing") {
extern crate image;
extern crate num_cpus;
use std::fs::File;
use std::thread;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::channel;
use std::cell::RefCell;
const WIDTH: u32 = 2048;
extern crate download;
use std::{io, fs};
use std::io::{Read, Write};
#[test]
fn test_open(){
let mut file = download::open("http://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz").unwrap();
println!("{:?}",file);