예제 #1
0
func main() {
	email := os.Getenv("SORACOM_EMAIL")
	password := os.Getenv("SORACOM_PASSWORD")

	if email == "" {
		fmt.Println("SORACOM_EMAIL env var is required")
		os.Exit(1)
		return
	}

	if password == "" {
		fmt.Println("SORACOM_PASSWORD env var is required")
		os.Exit(1)
		return
	}

	ac := soracom.NewAPIClient(nil)

	err := ac.Auth(email, password)
	if err != nil {
		fmt.Printf("auth err: %v\n", err.Error())
		return
	}

	subscribers, lek, err := ac.ListSubscribers(nil)
	if err != nil {
		fmt.Printf("err: %v\n", err.Error())
		return
	}

	pp.Print(subscribers)
	pp.Print(lek)
}
예제 #2
0
func loadConfig() {
	_, err := toml.DecodeFile(*conf, &config)
	if err != nil {
		log.Fatal(err)
	}
	pp.Print(config)
}
예제 #3
0
파일: demo.go 프로젝트: xboston/gegeo
func PointsAround() {

	gg := gegeo.GeGeoPoint{
		Id:    "123",
		Title: "Перви",
		Location: &gegeo.Location{
			Latitude:  55.7099235,
			Longitude: 60.5512079,
		},
	}

	log.Printf("%#v", gg)

	var query = map[string]interface{}{
		"size": 0,
		"aggregations": map[string]interface{}{
			"around": map[string]interface{}{
				// число точек вокруг текущей с группировкой по расстоянию
				"geo_distance": map[string]interface{}{
					"field": "geopoints.location",
					"origin": map[string]interface{}{
						"lat": gg.Location.Latitude,
						"lon": gg.Location.Longitude,
					},
					"unit": "km",
					"ranges": []interface{}{
						map[string]interface{}{
							"to": "10",
						},
						map[string]interface{}{
							"from": "10",
							"to":   "100",
						},
						map[string]interface{}{
							"from": "100",
						},
					},
				},
				"aggregations": map[string]interface{}{
					"district": map[string]interface{}{
						"terms": map[string]interface{}{
							"field": "metadate.addr:district",
							"size":  3,
						},
					},
				},
			},
		},
	}

	extraArgs := make(url.Values, 1)

	searchResults, err := connection.Search(query, []string{GEINDEX}, []string{GETYPE}, extraArgs)

	if err != nil {
		panic(err)
	}

	pp.Print(searchResults)
}
예제 #4
0
파일: main.go 프로젝트: shuichi/gordb
func main() {

	node, err := csv.Crawler("test")
	if err != nil {
		log.Fatalln(err)
	}
	const jsonStream = `{ 
		"union": {
			"input1": {"selection": {
				"input": { "relation": { "name": "dir1/staff2" } },
				"attr": "age",  "selector": ">=", "arg": 31
			}},
			"input2": {"selection": {
				"input": { "relation": { "name": "dir1/staff2" } },
				"attr": "name", "selector": "==", "arg": "山田"
			}}
		}
	}`
	m := core.Stream{}
	if err := json.NewDecoder(strings.NewReader(jsonStream)).Decode(&m); err != nil {
		log.Fatal(err)
	}
	result, err := core.StreamToRelation(m, node)
	if err != nil {
		log.Fatalln(err)
	}
	pp.Print(result)
}
예제 #5
0
파일: canga.go 프로젝트: jfontan/cangollo
func InfoCommand(c *cli.Context) {
	path := c.Args()[0]

	qemuImg := cangallo.QemuImg{}
	info, _ := qemuImg.Info(path)

	pp.Print(info)
}
예제 #6
0
파일: mp4tojpg.go 프로젝트: m0a/myGoSandBox
func main() {

	http.Handle("/", http.FileServer(http.Dir(".")))
	http.HandleFunc("/send", func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "POST" {
			pp.Print(r)
			//
			// out, err := os.Create("test.jpg")
			// if err != nil {
			// 	fmt.Printf("error %v", err)
			// 	return
			// }
			//
			// defer out.Close()
			//
			// _, err = io.Copy(out, r.Body)
			// if err != nil {
			// 	fmt.Printf("error %v", err)
			// 	return
			// }

			file, header, err := r.FormFile("file")

			if err != nil {
				fmt.Printf("error %v", err)
				return
			}

			defer file.Close()

			out, err := os.Create(header.Filename)
			if err != nil {
				fmt.Printf("error %v", err)
				return
			}

			defer out.Close()

			_, err = io.Copy(out, file)
			if err != nil {
				fmt.Printf("error %v", err)
				return
			}

			fmt.Printf("file upload success! %v", header.Filename)

		} else {
			fmt.Printf("Method is %v", r.Method)
		}

	})

	err := http.ListenAndServe(":9999", nil)
	if err != nil {
		log.Fatal("Error listening:", err)
	}

}
예제 #7
0
파일: main.go 프로젝트: plumbum/go-samples
func handle(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	pp.Print(ctx)
	authInfo := auth.FromContext(ctx)
	authInfo.UpdateHeaders(w.Header())
	if authInfo == nil || !authInfo.Authenticated {
		http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
		return
	}
	fmt.Fprintf(w, "<html><body><h1>Hello, %s!</h1></body></html>", authInfo.Username)
}
예제 #8
0
파일: main.go 프로젝트: dpetersen/grpc
func Search(c projects.ProjectsServiceClient, ctx context.Context, terms string) {
	req := &projects.ProjectsSearchRequest{SearchTerms: terms}

	log.Printf("Searching for '%s'", terms)
	resp, err := c.Search(ctx, req)
	if err != nil {
		log.Fatalf("could not search: %v", err)
	}

	log.Printf("Found %d of %d possible", resp.Results, resp.Known)
	pp.Print(resp.Projects)
}
예제 #9
0
파일: main.go 프로젝트: dpetersen/grpc
func Create(c projects.ProjectsServiceClient, ctx context.Context, id, name string) {
	uid := parseID(id)
	p := projects.Project{Id: uid, Name: name}
	created, err := c.Create(ctx, &p)
	if grpc.Code(err) == codes.AlreadyExists {
		log.Printf("that ID is taken")
		return
	} else if err != nil {
		log.Fatalf("could not create: %v", err)
		return
	}

	pp.Print(created)
}
예제 #10
0
파일: main.go 프로젝트: dpetersen/grpc
func Find(c projects.ProjectsServiceClient, ctx context.Context, id string) {
	uid := parseID(id)
	log.Printf("Finding '%d'", uid)
	proj, err := c.Get(ctx, &projects.ProjectRequest{Id: uid})
	if grpc.Code(err) == codes.NotFound {
		log.Printf("the project you wanted does not exist")
		return
	} else if err != nil {
		log.Fatalf("could not find: %v", err)
		return
	}

	pp.Print(proj)
}
예제 #11
0
파일: main.go 프로젝트: dpetersen/grpc
func SlowSearch(c projects.ProjectsServiceClient, ctx context.Context, terms string) {
	req := &projects.ProjectsSearchRequest{SearchTerms: terms}

	log.Printf("Slow Searching for '%s'", terms)
	stream, err := c.SlowSearch(ctx, req)
	if err != nil {
		log.Fatalf("could not slow search: %v", err)
	}

	for {
		prj, err := stream.Recv()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatalf("receiving slow search result: %v", err)
		}
		pp.Print(prj)
	}
}
예제 #12
0
// RegisterFace : アップロード画像の処理を行う
func RegisterFace(c web.C, w http.ResponseWriter, r *http.Request) {
	uuid := uuid.New()
	file, _, err := r.FormFile("body")
	if err != nil {
		fmt.Print(err.Error())
		w.WriteHeader(500)
	}
	defer file.Close()
	sourcePath := fmt.Sprintf("./tmp/%s", uuid)
	resultPath := fmt.Sprintf("./results/%s.jpg", uuid)
	fmt.Print(w, sourcePath)
	out, err := os.Create(fmt.Sprintf("./tmp/%s", uuid))
	if err != nil {
		fmt.Print(w, "fail to create")
		fmt.Print(err.Error())
		w.WriteHeader(500)
		return
	}
	defer out.Close()
	_, err = io.Copy(out, file)
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprintln(w, "faile to copy")
		fmt.Fprintln(w, err)
		return
	}

	img := getImg(sourcePath)
	defer C.cvReleaseImage(&img)
	faces := detect(img)
	rects := convertToRectagles(faces)
	pp.Print(rects)
	addRectanglesToImage(img, faces)
	saveImage(resultPath, img)

	http.Redirect(w, r, fmt.Sprintf("/face_detect/%s", uuid), http.StatusFound)
}
예제 #13
0
파일: web.go 프로젝트: kawaken/steward
func callback(c web.C, w http.ResponseWriter, r *http.Request) {
	integrationName := c.URLParams["name"]

	var integration Integration
	for _, intg := range conf.Integrations {
		if intg.Name == integrationName {
			integration = intg
		}
	}
	if integration.Name == "" {
		http.NotFound(w, r)
		return
	}

	code := r.FormValue("code")

	authConf := &oauth2.Config{
		ClientID:     integration.ClientID,
		ClientSecret: integration.ClientSecret,
		Endpoint: oauth2.Endpoint{
			AuthURL:  integration.AuthURL,
			TokenURL: integration.TokenURL,
		},
		RedirectURL: integration.RedirectURL,
	}

	tok, err := authConf.Exchange(oauth2.NoContext, code)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	fmt.Printf("%v\n", tok)
	pp.Print(tok)

	index(c, w, r)
}
예제 #14
0
파일: canga.go 프로젝트: jfontan/cangollo
func AddCommand(c *cli.Context) {
	image_file := c.Args()[0]

	repo := cangallo.Repo{}
	repo.Init()

	file, err := ioutil.TempFile("/tmp", "canga-")
	if err != nil {
		fmt.Printf("Can not create tempfile: %v\n", err)
		os.Exit(-1)
	}

	file.Write([]byte(cangallo.BasicImageText))

	file_name := file.Name()
	file.Close()

	data, err := cangallo.OpenEditor(file_name)
	GenericError(err)

	image := cangallo.Image{}

	err = yaml.Unmarshal(data, &image)
	if err != nil {
		fmt.Printf("Error parsing yaml: %v\n", err)
		os.Exit(-1)
	}

	temp_image_file, err := ioutil.TempFile(".", "canga-")
	if err != nil {
		fmt.Printf("Can not create tempfile: %v\n", err)
		os.Exit(-1)
	}

	temp_file_name := temp_image_file.Name()
	temp_image_file.Close()

	qemuImg := cangallo.QemuImg{}
	qemuImg.Clone(image_file, temp_file_name)

	sha1, err := cangallo.CalculateSHA1(temp_file_name)
	if err != nil {
		fmt.Printf("Error calculating SHA1: %v\n", err)
		os.Exit(-1)
	}

	dest_file_name := fmt.Sprintf("%s.qcow2", sha1)
	os.Rename(temp_file_name, dest_file_name)

	info, err := qemuImg.Info(dest_file_name)

	image.SHA1 = sha1
	image.TotalSize = info[0].ActualSize
	image.Size = info[0].VirtualSize
	image.Time = time.Now()

	pp.Print(image)

	repo.AddImage(sha1, image)

	pp.Print(repo.Index)

	repo.SaveIndex()
}
예제 #15
0
파일: canga.go 프로젝트: jfontan/cangollo
func ListCommand(c *cli.Context) {
	repo := cangallo.Repo{}
	repo.Init()

	pp.Print(repo)
}
예제 #16
0
파일: util.go 프로젝트: vozhyk-/gohan
func pprint(obj interface{}) {
	pp.Print(obj)
}