<commit_before>package hostqueue

import (
  "appengine"
  "appengine/datastore"

  "github.com/GoogleCloudPlatform/go-endpoints/endpoints"

  "log"
  "net/http"
  "time"
  )


func init() {
  http.HandleFunc("/action/email/", SendEmail)
  http.HandleFunc("/api/group", CreateGroup)
}

type Host struct {
	Id int64 `json:"id" datastore:"-"`
	HostName string `json:"hostName"`
	Emails []string `json:"emails"`
	TimesHosted int64 `json:"timesHosted"`
	LastHosted time.Time `json:"lastHosted"`
}

type Group struct {
    Id   int64  `json: "id" datastore:"-"`
    GroupName string `json:"groupName"`
    GroupEmail string `json:"groupEmail"`
    Hosts []Host `json:"hosts"`
    Next Host `json:"next"`
}

//Datastore methods from:  http://stevenlu.com/posts/2015/03/23/google-datastore-with-golang/
func (group *Group) key(c appengine.Context) *datastore.Key {
  // if there is no Id, we want to generate an "incomplete"
  // one and let datastore determine the key/Id for us
  if group.Id == 0 {
    return datastore.NewIncompleteKey(c, "Group", nil)
  }

  // if Id is already set, we'll just build the Key based
  // on the one provided.
  return datastore.NewKey(c, "Group", "", group.Id, nil)
}

func (group *Group) save(c appengine.Context) error {
  // reference the key function and generate it
  // accordingly basically its isNew true/false
  k, err := datastore.Put(c, group.key(c), group)
  if err != nil {
    return err
  }

  // The Id on the model is not prepopulated so we'll have
  // to append manually
  group.Id = k.IntID()
  return nil
}
<commit_msg>adding endpoints to add hosts and groups.<commit_after>package hostqueue

import (
  "appengine"
  "appengine/datastore"

  "github.com/GoogleCloudPlatform/go-endpoints/endpoints"

  "log"
  "net/http"
  "time"
  )


func init() {
  http.HandleFunc("/action/email/", SendEmail)
  http.HandleFunc("/api/group", CreateGroup)
}

type Host struct {
	Id int64 `json:"id" datastore:"-"`
	HostName string `json:"hostName"`
	Emails []string `json:"emails"`
	TimesHosted int64 `json:"timesHosted"`
	LastHosted time.Time `json:"lastHosted"`
}

type Group struct {
    Id   int64  `json: "id" datastore:"-"`
    GroupName string `json:"groupName"`
    GroupEmail string `json:"groupEmail"`
    Hosts []Host `json:"hosts"`
    Next Host `json:"next"`
}

// A QuotesAPI struct defines all the endpoints of the quotes API.
// It will have functions for CRUD like Add, List etc.
type GroupAPI struct {
}

// Add creates a new quote given the fields in AddRequest, stores it in the
// datastore, and returns it.
func (GroupAPI) Add(c context.Context, r *Group) (*Group, error) {
  // We set the same parent key on every Quote entity to ensure each Quote
  // is in the same entity group. Queries across the single entity group
  // will be consistent.
  k := datastore.NewIncompleteKey(c, "Group", quoteKey(c))

  //TODO: Oh my, trusing input from a user!!
  k, err := datastore.Put(c, k, r)
  if err != nil {
    return nil, err
  }
  t.UID = k
  return t, nil
}

//Datastore methods from:  http://stevenlu.com/posts/2015/03/23/google-datastore-with-golang/
func (group *Group) key(c appengine.Context) *datastore.Key {
  // if there is no Id, we want to generate an "incomplete"
  // one and let datastore determine the key/Id for us
  if group.Id == 0 {
    return datastore.NewIncompleteKey(c, "Group", nil)
  }

  // if Id is already set, we'll just build the Key based
  // on the one provided.
  return datastore.NewKey(c, "Group", "", group.Id, nil)
}

func (group *Group) save(c appengine.Context) error {
  // reference the key function and generate it
  // accordingly basically its isNew true/false
  k, err := datastore.Put(c, group.key(c), group)
  if err != nil {
    return err
  }

  // The Id on the model is not prepopulated so we'll have
  // to append manually
  group.Id = k.IntID()
  return nil
}

{'fraction_non_alphanumeric': 0.12935708752904726, 'fraction_numerical': 0.0077459333849728895, 'mean_word_length': 3.4324942791762014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589891', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1305, 'n_words': 427}