line integral versus complex integral Let $a\in \mathbb C, r>0$ and $\gamma_r=\partial D(0,r)$. I want to evaluate the following line integral
$$I=\int_{\gamma_r}\frac{1}{|z-a|^2}ds.$$
I'm looking for a complex function $g(z)$ such that
$$I=\int_{\gamma_r}g(z)dz.$$
I put $g(z)=\dfrac{1}{iz|z-a|^2}$. Then
$$\int_{\gamma_r}g(z)dz=\int_0^{2\pi}\frac{rie^{it}}{rie^{it}|re^{it}a|^2}dt=\frac{1}{r}I.$$
If $f(z)=\dfrac{1}{i|z-a|^2}$, I can apply Cauchy's integral formula to conclude
$$f(0)=\frac{1}{2\pi i}\int_{\gamma_r}\frac{f(z)dz}{z}dz=\frac{1}{2\pi i}\int_{\gamma_r}g(z)dz.$$
I find
$$I=r\int g(z)dz=2\pi r i f(0)=\frac{2\pi r}{|a|^2}.$$
Unfortunately, the correct solution should be
$$\dfrac{2\pi r}{| |a|^2-r^2|}.$$
Where did I go wrong?
 A: Let $z = re^{i\theta}$ on $\partial D(0, r)$. Then the length element is given in terms of $\theta$ by $ds = r d\theta$ an also we have $dz = iz \, d\theta$. Thus
$$ ds = \frac{r}{iz} dz.$$
This allows us to rewrite $I$ as
$$ I = \oint_{|z|=r} \frac{r}{iz \left| z - a \right|^2} \, dz. $$
To apply Cauchy integration formula, we must represent $I$ as an integral of meromorphic function. Note that
$$ r^2 = \left| z \right|^2 = z \bar{z}. $$
Thus
$$ \left|z - a \right|^2 = (z - a)(\bar{z} - \bar{a}) = (z - a)(r^2 z^{-1} - \bar{a}) $$
and hence $I$ can be written as
$$ I = \oint_{|z|=r} \frac{r}{iz (z - a)(r^2 z^{-1} - \bar{a})} \, dz = \frac{2\pi r}{2\pi i}\oint_{|z|=r} \frac{1}{(z - a)(r^2 - \bar{a} z)} \, dz.$$
To evaluate this integral, we divide into two cases according to the pole's position.
Case 1. Assume $|a| < r$, then $z = a$ is the unique pole of the integrand inside $D(0, r)$. Thus by Cauchy integration formula, we have
$$ I = 2\pi r \operatorname{Res}_{z = a} \frac{1}{(z - a)(r^2 - \bar{a} z)} = \frac{2\pi r}{r^2 - |a|}. $$
Case 2. Assume $|a| > r$, then $z = r^2 \bar{a}^{-1}$ is the unique pole of the integrand inside $D(0, r)$. Thus similarly we have
$$ I = 2\pi r \operatorname{Res}_{z = r^2 \bar{a}^{-1}} \frac{1}{(z - a)(r^2 - \bar{a} z)} = \frac{2\pi r}{(r^2 \bar{a}^{-1} - a)(-\bar{a})} = \frac{2\pi r}{|a|^2 - r^2}. $$
Combining two cases gives the desired answer.
