项目作者: orijtech

项目描述 :
Infrastructure management for Google Cloud Platform
高级语言: Go
项目地址: git://github.com/orijtech/infra.git
创建时间: 2017-05-30T07:17:02Z
项目社区:https://github.com/orijtech/infra

开源协议:Apache License 2.0

下载


infra Godoc

Cloud server infrastructure that is used to easily coordinate with Google Cloud Platform
with helpers for interacting with:

  • Google Cloud DNS
  • Google Compute Engine
  • Google Cloud Storage

With applications such as:

  • Setting up frontend servers fully connected to Google Cloud DNS, and proxying traffic
    to backends for example, if the program below is run, it’ll add Google Cloud DNS entries
    automatically, making the respective CNAMES, A records etc, and thus visiting the domain
    name or aliases will resolve and send traffic to the provided IPV4 addresses.
    ```go
    package main

import (
“fmt”
“log”

  1. "github.com/orijtech/infra"

)

func main() {
infraClient, err := infra.NewDefaultClient()
if err != nil {
log.Fatal(err)
}

  1. setupInfo, err := infraClient.FullSetup(&infra.Setup{
  2. Project: "sample-961732",
  3. Zone: "us-central1-c",
  4. ProjectDescription: "full-setup",
  5. MachineName: "full-setup-sample",
  6. DomainName: "edison.orijtech.com",
  7. ProxyAddress: "http://10.128.0.5/",
  8. Aliases: []string{"www.edison.orijtech.com", "el.orijtech.com"},
  9. IPV4Addresses: []string{"37.162.3.87"},
  10. })
  11. if err != nil {
  12. log.Fatal(err)
  13. }
  14. log.Printf("SetupResponse: %#v\n", setupInfo)

}

  1. - Creating a Google Compute Engine instance
  2. ```go
  3. package main
  4. import (
  5. "fmt"
  6. "log"
  7. "encoding/json"
  8. "github.com/orijtech/infra"
  9. )
  10. func main() {
  11. client, err := infra.NewDefaultClient()
  12. if err != nil {
  13. log.Fatal(err)
  14. }
  15. instance, err := client.CreateInstance(&infra.InstanceRequest{
  16. Description: "Git server",
  17. Project: "sample-998172",
  18. Zone: "us-central1-c",
  19. Name: "git-server",
  20. NetworkInterface: infra.BasicExternalNATNetworkInterface,
  21. })
  22. if err != nil {
  23. log.Fatal(err)
  24. }
  25. blob, _ := json.MarshalIndent(instance, "", " ")
  26. fmt.Printf("Retrieved instance: %s\n", blob)
  27. }
  • Add record sets to Google Cloud DNS
    ```go
    package main

import (
“fmt”
“log”

  1. "github.com/orijtech/infra"

)

func main() {
client, err := infra.NewDefaultClient()
if err != nil {
log.Fatal(err)
}
addRes, err := client.AddRecordSets(&infra.UpdateRequest{
Project: “sample-981058”,
Zone: “us-central1-c”,

  1. Records: []*infra.Record{
  2. {
  3. Type: infra.AName, DNSName: "git.orijtech.com.",
  4. IPV4Addresses: []string{"108.11.144.83"},
  5. },
  6. {Type: infra.CName, DNSName: "www.git.orijtech.com.", CanonicalName: "git.orijtech.com."},
  7. {Type: infra.CName, DNSName: "g.orijtech.com.", CanonicalName: "git.orijtech.com."},
  8. },
  9. })
  10. if err != nil {
  11. log.Fatalf("%+v", err)
  12. }
  13. fmt.Printf("addRes: %+v\n", addRes)

}

  1. - Uploading to Google Cloud Storage
  2. ```go
  3. package main
  4. import (
  5. "fmt"
  6. "io"
  7. "log"
  8. "strings"
  9. "github.com/orijtech/infra"
  10. )
  11. func main() {
  12. infraClient, err := infra.NewDefaultClient()
  13. if err != nil {
  14. log.Fatal(err)
  15. }
  16. outParams := &infra.UploadParams{
  17. Reader: func() io.Reader { return strings.NewReader("This is an upload") },
  18. Name: "foo",
  19. Bucket: "bucket",
  20. Public: true,
  21. }
  22. obj, err := infraClient.UploadWithParams(outParams)
  23. if err != nil {
  24. log.Fatalf("uploadWithParams: %v", err)
  25. }
  26. fmt.Printf("The URL: %s\n", infra.ObjectURL(obj))
  27. fmt.Printf("Size: %d\n", obj.Size)
  28. }