// createProfile receives a hash and an optional username. // If there is a username, it must be unique. func createProfile(u *url.URL, h http.Header, r *Auth) (int, http.Header, Response, error) { var err error p := new(profile.Profile) a := profile.NewAuth(r.Hash, r.Username) // if Getting an Auth succeeds, there was an existing row err = a.Get() if err == nil { return error400("auth exists", "hash:", *r.Hash) } a.Name = r.Name err = p.Create() if err != nil { return error500("db failure: p56", err.Error()) } a.Profile = p.Id err = a.Create() if err != nil { return error500("db failure: p62", err.Error()) } // if all is well... oh := http.Header{} oh.Add(ChuteToken, *a.Token) response := Profile{Id: p.Id, Created: p.Created} return http.StatusCreated, oh, response, nil }