func main() { conf_file.Read() if conf.Vals.Initialized == false { panic("the conf.Vals global conf struct has not been initialized") } iam_ready_chan := make(chan bool) go conf_iam.GoIAM(iam_ready_chan) iam_ready := <-iam_ready_chan if iam_ready { fmt.Printf("using iam\n") } else { fmt.Printf("not using iam\n") } s := scan.NewScan() tn := "test-godynamo-livetest" s.TableName = tn k_v1 := fmt.Sprintf("AHashKey%d", 100) s.ScanFilter["TheHashKey"] = scan.ScanFilter{AttributeValueList: []ep.AttributeValue{ep.AttributeValue{S: k_v1}}, ComparisonOperator: scan.OP_EQ} jsonstr, _ := json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err := s.EndpointReq() var r scan.Response um_err := json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } fmt.Printf("%v\n%v\n%v\n", body, code, err) s = scan.NewScan() s.TableName = tn jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReq() fmt.Printf("%v\n%v\n%v\n", body, code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } s.ScanFilter["SomeValue"] = scan.ScanFilter{AttributeValueList: []ep.AttributeValue{ ep.AttributeValue{N: "270"}, ep.AttributeValue{N: "290"}}, ComparisonOperator: scan.OP_BETWEEN} jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReq() fmt.Printf("%v\n%v\n%v\n", body, code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } k_v2 := fmt.Sprintf("AHashKey%d", 290) r_v2 := fmt.Sprintf("%d", 290) s.ExclusiveStartKey["TheHashKey"] = ep.AttributeValue{S: k_v2} s.ExclusiveStartKey["TheRangeKey"] = ep.AttributeValue{N: r_v2} jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReq() fmt.Printf("%v\n%v\n%v\n", body, code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } }
// ScanHandler relays the Scan request to Dynamo but first validates it through a local type. func ScanHandler(w http.ResponseWriter, req *http.Request) { if bbpd_runinfo.BBPDAbortIfClosed(w) { return } start := time.Now() if req.Method != "POST" { e := "scan_route.ScanHandler:method only supports POST" log.Printf(e) http.Error(w, e, http.StatusBadRequest) return } pathElts := strings.Split(req.URL.Path, "/") if len(pathElts) != 2 { e := "scan_route.ScanHandler:cannot parse path. try /create, call as POST" log.Printf(e) http.Error(w, e, http.StatusBadRequest) return } bodybytes, read_err := ioutil.ReadAll(req.Body) req.Body.Close() if read_err != nil && read_err != io.EOF { e := fmt.Sprintf("scan_route.ScanHandler err reading req body: %s", read_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } s := scan.NewScan() um_err := json.Unmarshal(bodybytes, s) if um_err != nil { e := fmt.Sprintf("scan_route.ScanHandler unmarshal err on %s to Create: %s", string(bodybytes), um_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } resp_body, code, resp_err := s.EndpointReq() if resp_err != nil { e := fmt.Sprintf("scan_route.ScanHandler:err %s", resp_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } if ep.HttpErr(code) { route_response.WriteError(w, code, "scan_route.ScanHandler", resp_body) return } mr_err := route_response.MakeRouteResponse( w, req, resp_body, code, start, scan.ENDPOINT_NAME) if mr_err != nil { e := fmt.Sprintf("scan_route.ScanHandler %s", mr_err.Error()) log.Printf(e) } }
func main() { home := os.Getenv("HOME") home_conf_file := home + string(os.PathSeparator) + "." + conf.CONF_NAME home_conf, home_conf_err := conf_file.ReadConfFile(home_conf_file) if home_conf_err != nil { panic("cannot read conf from " + home_conf_file) } home_conf.ConfLock.RLock() if home_conf.Initialized == false { panic("conf struct has not been initialized") } s := scan.NewScan() tn := "test-godynamo-livetest" s.TableName = tn k_v1 := fmt.Sprintf("AHashKey%d", 100) kc := condition.NewCondition() kc.AttributeValueList = make([]*attributevalue.AttributeValue, 1) kc.AttributeValueList[0] = &attributevalue.AttributeValue{S: k_v1} kc.ComparisonOperator = scan.OP_EQ s.ScanFilter["TheHashKey"] = kc jsonstr, _ := json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err := s.EndpointReqWithConf(home_conf) if err != nil || code != http.StatusOK { fmt.Printf("scan failed %d %v %s\n", code, err, body) } fmt.Printf("%v\n%v\n%v\n", string(body), code, err) var r scan.Response um_err := json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } s = scan.NewScan() s.TableName = tn jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReqWithConf(home_conf) if err != nil || code != http.StatusOK { fmt.Printf("scan failed %d %v %s\n", code, err, body) } fmt.Printf("%v\n%v\n%v\n", string(body), code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } kc = condition.NewCondition() kc.AttributeValueList = make([]*attributevalue.AttributeValue, 2) kc.AttributeValueList[0] = &attributevalue.AttributeValue{N: "270"} kc.AttributeValueList[1] = &attributevalue.AttributeValue{N: "290"} kc.ComparisonOperator = scan.OP_BETWEEN s.ScanFilter["SomeValue"] = kc jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReqWithConf(home_conf) fmt.Printf("%v\n%v\n%v\n", string(body), code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } k_v2 := fmt.Sprintf("AHashKey%d", 290) r_v2 := fmt.Sprintf("%d", 290) s.ExclusiveStartKey["TheHashKey"] = &attributevalue.AttributeValue{S: k_v2} s.ExclusiveStartKey["TheRangeKey"] = &attributevalue.AttributeValue{N: r_v2} jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReqWithConf(home_conf) if err != nil || code != http.StatusOK { fmt.Printf("scan failed %d %v %s\n", code, err, body) } fmt.Printf("%v\n%v\n%v\n", string(body), code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } }
func main() { conf_file.Read() conf.Vals.ConfLock.RLock() if conf.Vals.Initialized == false { panic("the conf.Vals global conf struct has not been initialized") } // launch a background poller to keep conns to aws alive if conf.Vals.Network.DynamoDB.KeepAlive { log.Printf("launching background keepalive") go keepalive.KeepAlive([]string{}) } // deal with iam, or not if conf.Vals.UseIAM { iam_ready_chan := make(chan bool) go conf_iam.GoIAM(iam_ready_chan) _ = <-iam_ready_chan } conf.Vals.ConfLock.RUnlock() s := scan.NewScan() tn := "test-godynamo-livetest" s.TableName = tn k_v1 := fmt.Sprintf("AHashKey%d", 100) kc := condition.NewCondition() kc.AttributeValueList = make([]*attributevalue.AttributeValue, 1) kc.AttributeValueList[0] = &attributevalue.AttributeValue{S: k_v1} kc.ComparisonOperator = scan.OP_EQ s.ScanFilter["TheHashKey"] = kc jsonstr, _ := json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err := s.EndpointReq() if err != nil || code != http.StatusOK { fmt.Printf("scan failed %d %v %s\n", code, err, body) } fmt.Printf("%v\n%v\n%v\n", string(body), code, err) var r scan.Response um_err := json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } s = scan.NewScan() s.TableName = tn jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReq() if err != nil || code != http.StatusOK { fmt.Printf("scan failed %d %v %s\n", code, err, body) } fmt.Printf("%v\n%v\n%v\n", string(body), code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } kc = condition.NewCondition() kc.AttributeValueList = make([]*attributevalue.AttributeValue, 2) kc.AttributeValueList[0] = &attributevalue.AttributeValue{N: "270"} kc.AttributeValueList[1] = &attributevalue.AttributeValue{N: "290"} kc.ComparisonOperator = scan.OP_BETWEEN s.ScanFilter["SomeValue"] = kc jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReq() fmt.Printf("%v\n%v\n%v\n", string(body), code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } k_v2 := fmt.Sprintf("AHashKey%d", 290) r_v2 := fmt.Sprintf("%d", 290) s.ExclusiveStartKey["TheHashKey"] = &attributevalue.AttributeValue{S: k_v2} s.ExclusiveStartKey["TheRangeKey"] = &attributevalue.AttributeValue{N: r_v2} jsonstr, _ = json.Marshal(s) fmt.Printf("JSON:%s\n", string(jsonstr)) body, code, err = s.EndpointReq() if err != nil || code != http.StatusOK { fmt.Printf("scan failed %d %v %s\n", code, err, body) } fmt.Printf("%v\n%v\n%v\n", string(body), code, err) um_err = json.Unmarshal([]byte(body), &r) if um_err != nil { e := fmt.Sprintf("unmarshal Response: %v", um_err) fmt.Printf("%s\n", e) } }