Beispiel #1
0
func NewListing(user *User, jsonReader io.Reader) (*Listing, error) {
	var rL RequestListing
	if err := json.NewDecoder(jsonReader).Decode(&rL); err != nil {
		return nil, err
	}

	if err := rL.validate(); err != nil {
		return nil, err
	}

	address, err := geo.Geocode(rL.Location.Address)
	if err != nil {
		return nil, err
	}

	balancedClient := balanced.NewClient(nil, os.Getenv("BALANCED_SECRET"))
	customer := balanced.Customer{Uri: user.CustomerUri}
	_, err = balancedClient.Customers.AddBankAccount(&customer, rL.BankAccountUri)
	if err != nil {
		return nil, err
	}

	path := generatePath()

	auth, err := aws.EnvAuth()
	if err != nil {
		return nil, err
	}
	s3Client := s3.New(auth, aws.USWest)
	bucket := s3Client.Bucket(os.Getenv("S3_BUCKET_NAME"))
	data, err := base64.StdEncoding.DecodeString(rL.Image)
	if err != nil {
		return nil, err
	}
	err = bucket.Put(path, data, "image/jpeg", s3.PublicRead)
	if err != nil {
		return nil, err
	}

	listing := Listing{
		Id:          bson.NewObjectId(),
		Title:       rL.Title,
		Description: rL.Description,
		Location: Location{
			Address: rL.Location.Address,
			Geometry: Geometry{
				Type:        "Point",
				Coordinates: []float64{address.Lng, address.Lat},
			},
		},
		Price:  rL.Price,
		Image:  bucket.URL(path),
		UserId: user.Id,
	}
	return &listing, nil
}
Beispiel #2
0
func (h *Hackathon) Geocode() error {
	address, err := geo.Geocode(h.Location)
	if err != nil {
		return err
	}

	h.Latitude = address.Lat
	h.Longitude = address.Lng

	return nil
}
Beispiel #3
0
func main() {
	var address *geo.Address
	var error error

	if isReverseMode() {
		latitude, longitude, ok := parseCoordinates()

		if ok != false {
			address, error = ReverseGeocode(latitude, longitude)
		}
	} else {
		query := strings.Join(os.Args[1:], " ")
		address, error = geo.Geocode(query)
	}

	if nil != error {
		fmt.Fprintln(os.Stderr, "Did not get any result")
		os.Exit(0)
	}

	fmt.Println(address)
}