Skip to content

Instantly share code, notes, and snippets.

func handleGetTweets(w http.ResponseWriter, r *http.Request) {
var maxIDQuery string
var tweets []Tweet
vars := mux.Vars(r)
userID := vars["id"]
// httpClient will automatically authorize http.Requests
httpClient := config.Client(oauth1.NoContext, token)
Outer:
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal(err)
}
// Load API credentials
config = oauth1.NewConfig(os.Getenv("APIKEY"), os.Getenv("APISECRET"))
token = oauth1.NewToken(os.Getenv("TOKEN"), os.Getenv("TOKENSECRET"))
// makeMuxRouter defines and creates routes
func makeMuxRouter() http.Handler {
muxRouter := mux.NewRouter()
muxRouter.HandleFunc("/{id}", handleGetTweets).Methods("GET")
return muxRouter
}
func respondWithError(err error, w http.ResponseWriter) {
log.Println(err)
w.WriteHeader(500)
// Tweet is a collection of important info in each Tweet
type Tweet struct {
Date string `json:"created_at"`
Text string `json:"text"`
ID string `json:"id_str"`
}
var config *oauth1.Config
var token *oauth1.Token
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
func (s *SmartContract) changeCarOwner(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {
if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2")
}
carAsBytes, _ := APIstub.GetState(args[0])
car := Car{}
json.Unmarshal(carAsBytes, &car)
// Block represents each 'item' in the blockchain
type Block struct {
Index int
Timestamp string
BPM int
Hash string
PrevHash string
Validator string
}
function transfer(address _to, uint256 _value) {
require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
}
func main() {
t := time.Now()
genesisBlock := Block{}
genesisBlock = Block{0, t.String(), 0, calculateHash(genesisBlock), ""}
Blockchain = append(Blockchain, genesisBlock)
// LibP2P code uses golog to log messages. They log with different
// string IDs (i.e. "swarm"). We can control the verbosity level for
// all loggers with:
func writeData(rw *bufio.ReadWriter) {
go func() {
for {
time.Sleep(5 * time.Second)
mutex.Lock()
bytes, err := json.Marshal(Blockchain)
if err != nil {
log.Println(err)
}