Exemple #1
0
func handlePOST(token *config.Token, domain *api.Domain, l *log.RequestLogger, r *responder.Responder, request *Request) {
	// Start domain update transaction
	trans, err := domain.StartTransaction(token.Domain)
	if err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Delete all existing records with same name and type
	if err := trans.DeleteRecords(request.Name, token.Type); err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Add new record to domain
	if err := trans.AddRecord(request.Name, token.Type, request.Value, token.TTL); err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Commit changes to domain
	if err := trans.Commit(); err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Send success response
	r.Success()
	l.Message(fmt.Sprintf("Added [%s] '%s' - '%s' to domain '%s'", token.Type, request.Name, request.Value, token.Domain))
}
Exemple #2
0
func handleDELETE(token *config.Token, domain *api.Domain, l *log.RequestLogger, r *responder.Responder, recordName string) {
	// Start domain update transaction
	trans, err := domain.StartTransaction(token.Domain)
	if err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Delete all existing records with same name and type
	if err := trans.DeleteRecords(recordName, token.Type); err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Commit changes to domain
	if err := trans.Commit(); err != nil {
		r.Error(err)
		l.Error(err)
		return
	}

	// Send success response
	r.Success()
	l.Message(fmt.Sprintf("Removed all [%s] '%s' records from domain '%s'", token.Type, recordName, token.Domain))
}