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
// 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);
@deankarn
deankarn / download.rs
Created May 5, 2017 18:43
download.rs
extern crate hyper;
extern crate crypto;
use std::{env, result};
use std::path::Path;
use std::{io, fs};
use std::io::{Read, Write, Seek, SeekFrom};
use hyper::Client;
use hyper::status::StatusCode;