This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use aws_sdk_sts as sts; | |
use std::env; | |
#[tokio::main] | |
async fn main() { | |
let config = aws_config::load_from_env().await; | |
let client = sts::Client::new(&config); | |
let token_code = env::args().nth(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{thread, time::Duration}; | |
mod sync_primitives { | |
use std::sync::atomic::{AtomicUsize, Ordering}; | |
use std::sync::{Arc, Condvar, Mutex}; | |
struct Wg { | |
counter: AtomicUsize, | |
mu: Mutex<bool>, | |
condvar: Condvar, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn wait(&self) { | |
let mut started = self.0.mu.lock().unwrap(); | |
while !*started { | |
started = self.0.condvar.wait(started).unwrap(); | |
if self.0.counter.load(Ordering::Relaxed) == 0 { | |
*started = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Clone for WaitGroup { | |
fn clone(&self) -> Self { | |
self.0.counter.fetch_add(1, Ordering::Relaxed); | |
Self(self.0.clone()) | |
} | |
} | |
impl Drop for WaitGroup { | |
fn drop(&mut self) { | |
self.0.counter.fetch_sub(1, Ordering::Relaxed); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::atomic::AtomicUsize; | |
use std::sync::{Condvar, Mutex}; | |
struct Wg { | |
counter: AtomicUsize, | |
mu: Mutex<bool>, | |
condvar: Condvar, | |
} | |
impl Wg { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/pandulaDW/go-json-to-proto/transactions" | |
"google.golang.org/protobuf/proto" | |
"log" | |
"os" | |
"time" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package transactions | |
import ( | |
"encoding/binary" | |
"google.golang.org/protobuf/proto" | |
"io" | |
"os" | |
) | |
func WriteProtoToFile(filepath string, allTransactions []*TransactionJsonType) error { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buf := make([]byte, 4) | |
if _, err := file.ReadAt(buf, offset); err != nil { | |
if err == io.EOF { | |
break | |
} | |
return nil, err | |
} | |
itemSize := binary.LittleEndian.Uint32(buf) | |
offset += 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// writing the length of the encoded item before writing the data | |
buf := make([]byte, 4) | |
binary.LittleEndian.PutUint32(buf, uint32(len(encodedData))) | |
if _, err := outFile.Write(buf); err != nil { | |
return err | |
} | |
// writing the actual transaction item to the file | |
if _, err := outFile.Write(encodedData); err != nil { | |
return err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package transactions | |
func toProtoSingleTransaction(obj *SingleJsonTransaction) *SingleTransaction { | |
return &SingleTransaction{ | |
Date: obj.Date.Date.UnixNano(), | |
Amount: obj.Amount, | |
TransactionCode: obj.TransactionCode, | |
Price: obj.Price, | |
Total: obj.Total, | |
} |
NewerOlder